Use this for any container that needs to be treated like a real background service, not something you manually babysit.
Steps
- In
docker-compose.yml, addrestart: unless-stoppedunder the service definition. - Apply it:
docker compose down && docker compose up -d. - That's genuinely it, no daemon config, no external process manager needed.
Gotcha
restart: unless-stopped means the container restarts after a crash or a full machine reboot, but not if you manually stopped it yourself (docker compose down or docker stop). If you want it to come back even after a manual stop, the option is always instead, though for most personal projects unless-stopped is the safer default, since it respects an intentional stop.
Also worth knowing: this only restarts the container. If the whole machine reboots, Docker Desktop itself also needs to be set to auto-start, otherwise there's nothing to restart the container in the first place.
Quick reference
services:
app:
restart: unless-stopped