I recently set up two different containerized apps with docker compose up -d
. However, I discovered after a reboot that one of the applications started back up all on its own, while the other did not.
Turns out, you actually have to check and set the restart policy of your containers. Here’s the command to do this:
docker inspect --format='{{.Name}} {{.HostConfig.RestartPolicy.Name}}' $(docker ps -q)
Running this against the machine where I host Dify gave the following results:
/docker-nginx-1 always
/docker-worker-1 always
/docker-api-1 always
/docker-weaviate-1 always
/docker-db-1 always
/docker-sandbox-1 always
/docker-redis-1 always
/docker-ssrf_proxy-1 always
/docker-web-1 always
Sure enough, this machine always restarts its containers on boot. Running the same command on the machine where I host Seafile gave these results:
/seafile no
/seafile-mysql no
/seafile-memcached no
Not surprisingly, this machine had been forcing me to log in and start containers manually with docker compose up -d
on each boot.
So how do I fix it? Link to heading
Luckily, it was an easy fix. The command is:
docker update --restart always <container_id>
Simply run this against each container you want to restart. Want to run it against all running containers?. Just use this command:
docker update --restart always $(docker ps -q)
Easy peasy!