Tms91
Tms91

Reputation: 4214

Docker: Why does --rm does not remove my container as I exit from it

I'm running Docker on Windows10.

adding --rm to a docker container run command should remove my container as I exit from it, but since a while, if I type

docker container run -p 80:80 --rm nginx

I get

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up

and nginx runs well on my docker-machine IP address, but then if I type

ctrl+C

and I check my conainers with docker container ls I see that container is still running:

$ docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
012963897aa4        nginx               "/docker-entrypoint.…"   2 minutes ago       Up 2 minutes        0.0.0.0:80->80/tcp   affectionate_dhawan

Why?

Upvotes: 5

Views: 4645

Answers (1)

iBug
iBug

Reputation: 37317

adding --rm to a docker container run command should remove my container as I exit from it.

This is a misconception. The --rm flag tells Docker to remove the container when it stops.

I see you passed no extra flags to your docker container run command, so I'll assume you attach to your container after starting it. Detaching from a container does not stop it automatically, unless the container is started with the -i flag, which should automatically attach stdin/stdout to the container with that run command.

To remove a container that was started with --rm flag, you cam simply docker stop it and it'll be gone.

Upvotes: 10

Related Questions