Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create and delete Docker containers in Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to create and delete Docker containers in Linux. I think it is very practical, so I share it with you. I hope you can get something after reading this article.

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 ps CONTAINER 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-a CONTAINER 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) what is the Linux system Linux is a free to use and freely spread UNIX-like operating system, is a POSIX-based multi-user, multi-tasking, multi-threading and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

The above is how to create and delete Docker containers in Linux. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report