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: force Docker Compose to recreate a container whose settings did not change

Docker
~/tips/tip-docker-compose-force-recreate

docker compose up -d --force-recreate web

Throw away and recreate a service's containers when a fresh start is the fix.

docker compose up -d leaves a container alone when its configuration has not changed. Sometimes you want a fresh container anyway, and --force-recreate gives you one.

docker compose up -d --force-recreate web

Compose removes the container for web and creates a new one from the same image and settings. Volumes are kept, so data in named volumes and bind mounts survives. Whatever the container wrote into its own filesystem does not.

Reasons I would use it: a container whose writable layer got into a weird state, a bind mounted single file that was replaced on the host (the container keeps the old inode, which is a classic trap), or an image with the same tag that you just pulled and want to be sure is used.

Leave out the service name and every service in the project is recreated, which also means downtime for all of them. I would always name the one I mean.

The opposite flag exists too: --no-recreate keeps existing containers even when the file changed. The two cannot be combined. And if dependent services need a fresh start as well, --always-recreate-deps takes care of those, so you do not have to list them all.

Further reading: 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