Doubt about docker-compose down and docker-compose rm commands

Hi, i have a question about two commands: docker-compose down and docker-compose rm

I have a different directories for every docker-compose.yml, so when i build containers i jump from dir to dir performing docker-compose up -d

Now, what happens if i want to remove a container? or its image also? I just have to go into the directory where its yml file resides and perform the down command? Or i should use the rm command?

Thanks in advance!

Let me execute docker-compose --help for you:

...
down               Stop and remove containers, networks, images, and volumes
...
rm                 Remove stopped containers
...

That’s why i’m in doubt, basically they do the same thing, but “down” works also on networks, images, and volumes?

I am not realy sure how to respond to that :rofl:

rm - won’t remove a container if it’s running. It only removes already stopped containers
down - will stop a running container AND remove it as well. In addition to that it will remove networks, images and volumes

1 Like

The ‘down’ option execute the ‘stop’ and ‘rm’ options ( in that order ), plus remove containers and managed networks; and if add the ‘-v’ extra flag, can delete the volumes too.