Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between 'down' and 'rm' in docker/docker-compose?

The docs for docker-compose down, docker-compose rm, and docker rm all read very similarly. What's the difference? And when would you use one over the others?

like image 920
BlueRaja - Danny Pflughoeft Avatar asked Oct 16 '22 15:10

BlueRaja - Danny Pflughoeft


1 Answers

  • "docker-compose down": stop and remove the container with all the networks (but not volumes), you should add -v option to do that.
  • "docker-compose rm": remove stopped only containers, but not running containers, you should add option -s to be able to remove running containers

Now, the diffrence between "docker-compose rm" and "docker rm", is that when you make changes affecting the container in the docker-compose.yml file, you can't remove the container created by the old docker-compose.yml using "docker-compose rm", so in this case you should use "docker rm" to do that.

If you still don't get it, you can try this example:

  1. Run a container using "docker-compose up"
  2. Now stop the container without removing it using "docker-compse stop"
  3. Change the name of the container in the docker-compose.yml
  4. Run "docker-compose up" --> a new container will be created with the new name.
  5. Now if you try to remove the old container using "docker-compose rm old_container_name", you will get this error: No such service.
  6. In this case you can only remove the old container using "docker container rm old_container_name".
like image 103
Ali ELLOUZE Avatar answered Oct 19 '22 02:10

Ali ELLOUZE