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 unless-stopped remembers that you stopped a container, always does not

Docker
~/tips/tip-docker-unless-stopped-vs-always

docker run -d --name web --restart unless-stopped nginx:alpine

Pick the restart policy that respects a container you stopped on purpose.

Both always and unless-stopped bring a crashed container back. The difference shows up after a reboot or a Docker update, and it decides whether a container you switched off stays off.

docker run -d --name web --restart unless-stopped nginx:alpine

With always, a container you stopped by hand comes back as soon as the Docker daemon restarts. With unless-stopped, Docker remembers that you stopped it and leaves it down, even across daemon restarts. In Compose it is the same: restart: unless-stopped.

For a home server I find unless-stopped the better default. If I stop a test container to save memory, I do not want it to come back after the next update. I would keep always for the handful of things that must run no matter what, like a reverse proxy.

There is a detail in the docs that explains a lot of confusing restart behaviour: a restart policy only kicks in after the container has started successfully, meaning it was up for at least ten seconds. Docker also waits longer before each new restart, doubling from 100 milliseconds, so a crash loop does not hammer your machine. Use docker update --restart to change the policy of an existing container.

Further reading: Start containers automatically

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