Summary of methods for creating, listing, and deleting Docker containers on Linux

Summary of methods for creating, listing, and deleting Docker containers on Linux

1. Start the Docker container

Start a new Docker container using the command below. This will start a new container and give you access to it using the /bin/bash shell.

# docker run [OPTIONS] <IMAGE NAME> [COMMAND] [ARG...]

For example, the command below will create a new docker container using the image named "ubuntu". To list all available images, use the docker images command.

# docker run -i -t ubuntu /bin/bash

To exit the Docker container, press ctrl+p+q. This will keep the container running in the background and provide the host system console. If you use the exit command, it will stop the current container.

2. List Docker containers

Once inside the Docker container, execute the following command to list all running containers.

# docker ps

 

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

f2582758af13 ubuntu "/bin/bash" 2 hours ago Up 2 hours first_ubuntu

By default, the command above will only list running containers. To list all containers including stopped ones, you need to use the following command.

# docker ps -a

 

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

f2582758af13 ubuntu "/bin/bash" 2 hours ago Up 2 hours first_ubuntu

6b5b5a969241 centos "/bin/bash" 2 days ago Exited (0) 24 hours ago ubuntu-web

3. Start/Stop/Connect Container

You can start, stop, or attach to any container using the following commands. To start the container, use the following command.

# docker start <CONTAINER ID|NAME>

To stop the container, use the following command.

# docker stop <CONTAINER ID|NAME>

To attach to the currently running container, use the following command.

# docker attach <CONTAINER ID|NAME>

4. Discard Docker containers

Before deleting any container, make sure the container is stopped. You can list the status of the container using the 'docker ps -a' command. If the container is still running, first stop it using the given command in the above steps.

Now remove single or multiple containers using the following command.

# docker rm <CONTAINER ID|NAME> <CONTAINER ID|NAME>

You can also remove all stopped containers at once using the following command.

# docker rm $(docker ps -a -q)

You may also be interested in:
  • Solution to the Docker container cannot be stopped and deleted
  • Docker stop stops/remove deletes all containers
  • How to delete the container created in Docker
  • Docker learning notes: How to view, start, terminate and delete containers
  • Docker Tips: Deleting Docker Containers and Images
  • Solution to the problem that Docker cannot stop or delete container services

<<:  Detailed example of clearing tablespace fragmentation in MySQL

>>:  How to introduce scss into react project

Recommend

Teach you how to deploy zabbix service on saltstack

Table of contents Saltstack deploys zabbix servic...

Installation tutorial of MySQL 5.7 green version under windows2008 64-bit system

Preface This article introduces the installation ...

Basic usage of find_in_set function in mysql

Preface This is a new function I came across rece...

Understanding v-bind in vue

Table of contents 1. Analysis of key source code ...

MySQL automatically inserts millions of simulated data operation code

I use Navicat as my database tool. Others are sim...

MySQL 5.7 zip archive version installation tutorial

This article shares the installation tutorial of ...

Use of Vue3 table component

Table of contents 1. Ant Design Vue 1. Official w...

The front-end page pop-up mask prohibits page scrolling

A problem that front-end developers often encount...

Summary of MySQL database usage specifications

Introduction: Regarding MySQL database specificat...

Introduction to new features of MySQL 8.0.11

MySQL 8.0 for Windows v8.0.11 official free versi...

Linux completely removes node.js and reinstalls it through the yum command

first step Delete it once with the built-in packa...

Tutorial on Installing Nginx-RTMP Streaming Server on Ubuntu 14

1. RTMP RTMP streaming protocol is a real-time au...

Two ways to configure Vue global methods

Table of contents 1. Introduction 2. The first me...