删除列出的Docker ps -f状态=创建的Docker容器是否安全?

时间:2022-01-02 07:25:48

I've already seen posts showing how to remove exited containers listed with docker ps -q -f status=exited, but I also want to clean up 'created' but not 'running' containers. Is it safe to remove containers with the 'created' status, or is there a downside to this?

我已经看到了一些帖子,展示了如何删除使用docker ps -q -f状态的退出容器,但我也希望清理“创建”但不是“运行”容器。移除“创建”状态的容器是否安全,或者这是否有负面影响?

2 个解决方案

#1


4  

Docker containers with created status are containers which are created from the images, but never started. Removing them has no impact as you would not have run any process within the container and causing a change in the state of the created container, in the later case requires to be committed. This is generally done to speed up starting the container and making sure all the configuration is kept ready.

具有创建状态的Docker容器是由映像创建的容器,但从未启动。删除它们没有影响,因为您不会在容器中运行任何进程,并导致创建的容器的状态发生变化,在以后的情况下需要提交。这通常是为了加速启动容器并确保所有配置都准备就绪。

Refer Docker Docs

码头工人参考文档

The docker create command creates a writeable container layer over the specified image and prepares it for running the specified command. The container ID is then printed to STDOUT. This is similar to docker run -d except the container is never started. You can then use the docker start command to start the container at any point.

docker create命令在指定的映像上创建一个可写的容器层,并为运行指定的命令做准备。然后将容器ID打印到STDOUT。这类似于docker run -d,但容器从未启动。然后,您可以使用docker start命令在任何点启动容器。

This is useful when you want to set up a container configuration ahead of time so that it is ready to start when you need it. The initial status of the new container is created.

当您希望提前设置容器配置时,这是非常有用的,以便在您需要时可以启动它。创建新容器的初始状态。

#2


0  

There is two possibility for a container to be in the created status :

在创建的状态中,容器有两种可能:

  1. As explained by @askb docker container created from the image using docker create command will end up in the create command
  2. 正如使用docker create命令从映像创建的@askb docker容器所解释的那样,将在create命令中结束。
  3. A docker container created by the run command but not able to start. Multiple causes here but the easiestone is a docker container with a port mapping to an already bind ones
  4. 由run命令创建的docker容器,但不能启动。这里有多个原因,但最简单的是docker容器,它的端口映射到已经绑定的端口。

To answer the question, in both cases, removing them is safe.

为了回答这个问题,在这两种情况下,移除它们都是安全的。

A way to reproduce the docker container in a created state via the run command is :

通过run命令在创建状态中复制docker容器的方法是:

docker pull loicmathieu/vsftpd
docker run -p 621:21 -d  loicmathieu/vsftpd ftp
docker run -p 621:21 -d  loicmathieu/vsftpd ftp

Then docker ps -a will give you something like

然后docker ps -a会给你一些类似的东西。

CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS
e60dcd51e4e2        loicmathieu/vsftpd     "/start.sh ftp"          6 seconds ago       Created
7041c77cad53        loicmathieu/vsftpd     "/start.sh ftp"          16 seconds ago      Up 15 seconds

#1


4  

Docker containers with created status are containers which are created from the images, but never started. Removing them has no impact as you would not have run any process within the container and causing a change in the state of the created container, in the later case requires to be committed. This is generally done to speed up starting the container and making sure all the configuration is kept ready.

具有创建状态的Docker容器是由映像创建的容器,但从未启动。删除它们没有影响,因为您不会在容器中运行任何进程,并导致创建的容器的状态发生变化,在以后的情况下需要提交。这通常是为了加速启动容器并确保所有配置都准备就绪。

Refer Docker Docs

码头工人参考文档

The docker create command creates a writeable container layer over the specified image and prepares it for running the specified command. The container ID is then printed to STDOUT. This is similar to docker run -d except the container is never started. You can then use the docker start command to start the container at any point.

docker create命令在指定的映像上创建一个可写的容器层,并为运行指定的命令做准备。然后将容器ID打印到STDOUT。这类似于docker run -d,但容器从未启动。然后,您可以使用docker start命令在任何点启动容器。

This is useful when you want to set up a container configuration ahead of time so that it is ready to start when you need it. The initial status of the new container is created.

当您希望提前设置容器配置时,这是非常有用的,以便在您需要时可以启动它。创建新容器的初始状态。

#2


0  

There is two possibility for a container to be in the created status :

在创建的状态中,容器有两种可能:

  1. As explained by @askb docker container created from the image using docker create command will end up in the create command
  2. 正如使用docker create命令从映像创建的@askb docker容器所解释的那样,将在create命令中结束。
  3. A docker container created by the run command but not able to start. Multiple causes here but the easiestone is a docker container with a port mapping to an already bind ones
  4. 由run命令创建的docker容器,但不能启动。这里有多个原因,但最简单的是docker容器,它的端口映射到已经绑定的端口。

To answer the question, in both cases, removing them is safe.

为了回答这个问题,在这两种情况下,移除它们都是安全的。

A way to reproduce the docker container in a created state via the run command is :

通过run命令在创建状态中复制docker容器的方法是:

docker pull loicmathieu/vsftpd
docker run -p 621:21 -d  loicmathieu/vsftpd ftp
docker run -p 621:21 -d  loicmathieu/vsftpd ftp

Then docker ps -a will give you something like

然后docker ps -a会给你一些类似的东西。

CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS
e60dcd51e4e2        loicmathieu/vsftpd     "/start.sh ftp"          6 seconds ago       Created
7041c77cad53        loicmathieu/vsftpd     "/start.sh ftp"          16 seconds ago      Up 15 seconds