5

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?

Blake
  • 53
  • 1
  • 5

2 Answers2

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.

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.

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.

tlo
  • 1,571
  • 1
  • 25
  • 38
askb
  • 6,501
  • 30
  • 43
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. 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

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 :

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

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
loicmathieu
  • 5,181
  • 26
  • 31