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

nginx proxy_cache batch cache clearing script introduction

Preface: I used the official nginx proxy_cache as...

Detailed explanation of MySQL InnoDB index extension

Index extension: InnoDB automatically extends eac...

Tips for using DIV container fixed height in IE6 and IE7

There are many differences between IE6 and IE7 in ...

Use of Docker UI, a Docker visualization management tool

1. Introduction to DockerUI DockerUI is based on ...

Disable autocomplete in html so it doesn't show history

The input box always displays the input history wh...

Sample code for implementing Google third-party login in Vue

Table of contents 1. Developer Platform Configura...

Realizing tree-shaped secondary tables based on angular

First look at the effect: Code: 1.html <div cl...

Example of Vue uploading files using formData format type

In Vue, we generally have front-end and back-end ...

The use and difference between JavaScript pseudo-array and array

Pseudo-arrays and arrays In JavaScript, except fo...

W3C Tutorial (2): W3C Programs

The W3C standardization process is divided into 7...

Usage of the target attribute of the html tag a

1: If you use the tag <a> to link to a page,...

Introduction to installing JDK under Linux, including uninstalling OpenJDK

1. View openjdk rpm -qa|grep jdk 2. Delete openjd...

CSS Viewport Units for Fast Layout

CSS Viewport units have been around for the past ...