Get the App
SLTechnology News&Howtos  ›  Servers  › 

Methods for creating, listing, and deleting Docker containers on Linux

Shulou Source: shulou.com Published: 2022-06-02 04:36:15 09月25日 Update

Editor to share with you how to create, list and delete Docker containers on Linux. I hope you will learn a lot after reading this article. Let's discuss it together.

1. Start the Docker container

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

# docker run [OPTIONS] [COMMAND] [ARG...]

For example, the following command creates a new docker container using an 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 allow the container to run in the background and provide the host system console. If you use the exit command, it stops the current container.

2. List Docker containers

Once it exists from the Docker container, execute the following command to list all the running containers.

# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf2582758af13 ubuntu "/ bin/bash" 2 hours ago Up 2 hours first_ubuntu

By default, the above command lists only the containers that are running. To list all containers, including those that have been stopped, use the following command.

# docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf2582758af13 ubuntu "/ bin/bash" 2 hours ago Up 2 hours first_ubuntu6b5b5a969241 centos "/ bin/bash" 2 days ago Exited (0) 24 hours ago ubuntu-web

3. Start / stop / connect the container

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

# docker start

To stop the container, use the following command.

# docker stop

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

# docker attach

4. Discard the Docker container

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

Now use the following command to delete single or multiple containers.

# docker rm

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

# docker rm $(docker ps-a-Q) after reading this article, I believe you have some understanding of how to create, list and delete Docker containers on Linux. If you want to learn more about it, please follow the industry information channel. Thank you for reading!

Tags: Container command run current face method you can make image use article attach host single background multiple finished case console more permissions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno vpn macOS Shulou Information