brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker compose down --remove-orphans cleans up services you removed from the file

Docker
~/tips/tip-compose-down-remove-orphans

docker compose down --remove-orphans

Removes containers left behind by services you deleted or renamed in the compose file.

If you rename or delete a service in your compose file, its old container stays behind, still running and still using the port. --remove-orphans finds those leftovers.

The option removes containers for services that are not defined in the Compose file. Compose knows which containers belong to the project, so it can tell which ones no longer match the file.

docker compose down --remove-orphans

It works with up as well, which is handy if you do not want to stop everything:

docker compose up -d --remove-orphans

The scenario I have in mind: you rename the service web to app, run docker compose up -d, and get a warning about an orphan container while the old web container is still running. One of the two commands above removes it.

down without extra flags removes containers and networks, but not named volumes. The -v option is the one that removes named volumes declared in the file and anonymous volumes, so I would never add it out of habit, because it deletes data. Also check the container list with docker compose ps first if you share one project name between several folders, since an orphan from the point of view of one file could be a service you meant to keep.

Further reading: docker compose down, docker compose up

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link