we have deployed docker container and the restart policy is --restart unless-stopped. This will start the container after VM reboot. The docker service is also enabled to start the service after reboot.
The problem is whenever reboot happen, the list of containers and images all are gone. Solution for this is to restart the docker service. so after this container is coming up.
so question is why do we need to restart the docker service even after it is enabled to start after reboot?
appreciate help on this?
I don't know the truly internals of Docker Engine, but I make my assumptions:
On Virtual Machine (or native host) restart, the docker engine is stopped, so the containers receive a "stop" signal too (in background a systemctl stop docker will be performed)
What you are doing with systemctl restart docker (or similar command) is sending a "restart" signal to the docker engine, not a "stop" one.
You should use --restart always if you want to be sure that the containers are restarted automatically when the VM is freshly started/restarted.
Related
I am running a docker service in swarm mode. When I want to restart it, there are 2 options I know:
from swarm manager: docker service scale myservice=0 then docker service scale myservice=1
from server running the server: docker ps, take the container id of my service and do docker stop <containerId>
And this works fine. However, if I go with option #2 and instead of docker stop I write docker restart it will restart the current instance, but because being in swarm mode it will also start a new one. So in the end I will end up having 2 of the same service, even though in my compose I have specified I want only 1 replica.
Is there any way to prevent docker restart and the docker swarm to start a 2nd service while one is already there?
I am using docker 18.09.2 on ubuntu 18.04
Can someone explain me why after host machine reboot all containers are exited?How can i find a way to restart containers specially rancher containers and everything be as before?
You can use the docker restart policy to control container automatic startup. Check Start containers automatically for more info.
As for the current container that are stopped you need to start them manually:
docker ps -a
docker start <container>
Run docker container on a Linux system. From docker ps can see all the processes.
After restart the system and run docker ps can't see some containers, but use docker ps -a can see them. Is the container still running?
If you don't set the option --restart=always when run the docker container, these containers will not be started automatically, after you restart the system.
Restart policies (–restart)
always - Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container.
Refer: docker run - Restart policies (–restart)
I would like the docker containers to come up
On host reboot or when docker is restarted on host
On failure with maximum retries .
I am aware that the docker restart policies unless-stopped and always are in the same direction but I would want them to fail after maximum retries.
Thinking of below steps as a solution
No restart policy on docker containers
systemd-docker to restart containers on-failure and enabled on reboot.
is there a better way to do this?
I would like the docker containers to come up On host reboot or when docker is restarted on host
This is not a complete answer, but know that docker 1.12 will add a daemonless container mode
(PR 23213):
Daemonless Containers
Starting with Docker 1.12 containers can run without Docker or containerd running.
This allows the Docker daemon to exit, be upgraded, or recover from a crash without affecting running containers on the system.
To enable this functionality you need to add the --live-restore flag when launching dockerd. This will ensure that Docker does not kill containers on graceful shutdown or on restart leaving the containers running.
I was having a network issue, so I restarted my local machine, which also aborted my docker default VM. So I ran the below command to restart my virtualbox instance docker-machine restart default.
I previously had built containers on default, but I want to know, do I need to rebuild those same containers now that I restarted default, or can I just run docker-compose up?
They are not destroyed. They are stopped though. You can check with
docker ps -a
This will show all containers, stopped and running. In order to start a container
docker start <container name or container id>