How to Ensure Containers Restarts Automatically After Docker Daemon Restarts
1.1.2024

Whenever you start the container, you can use the --restart
flag to tell Docker to always restart the container if it stops. This is useful for services that need to be kept running, such as databases and web servers.
The default is not to restart the conrtainer.
Now here is the problem i had in my pop_os machine. According to the documentation of docker, if i set policy to always
and stop the container manually (with docker stop
command) the container only will restart if the docker daemon restarts or the container itself is manually restarted source.
Here are the commands I was running:
# 1. Start the container
docker run --it --name always --restart always alpine ash
# 2. Stop the container
docker stop always
# 3. restart the docker daemon
sudo systemctl restart docker
But my docker container didn’t restarted unfortunately 😢.
So i couldn’t solve this problem by using systemctl
but what it did worked for me was to restart docker daemon by using Docker Desktop.