Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start the docker daemon without starting containers that set to restart automatically

Tags:

docker

The docker daemon isn't starting anymore on my computer (Linux / Centos 7), and I strongly suspect that a container that is set to auto-restart is to blame in this case. If I start the daemon manually, the last line I see is "Loading containers: start", and then it just hangs.

What I'd like to do is to start the daemon without starting any containers. But I can't find any option to do that. Is there any option in docker to start the daemon without also starting containers set to automatically restart? If not, is there a way to remove the containers manually that doesn't require the docker daemon running?

like image 272
Mad Scientist Avatar asked Apr 03 '18 08:04

Mad Scientist


People also ask

How do I stop my Docker container from automatically restarting?

You can use the --restart=unless-stopped option, as @Shibashis mentioned, or update the restart policy (this requires docker 1.11 or newer); See the documentation for docker update and Docker restart policies. Use docker update --restart=no $(docker ps -a -q) to update all your containers :-) Great answer!!

Can I restart Docker daemon without restarting Docker container?

Restart the Docker daemon. On Linux, you can avoid a restart (and avoid any downtime for your containers) by reloading the Docker daemon. If you use systemd , then use the command systemctl reload docker . Otherwise, send a SIGHUP signal to the dockerd process.

Does restarting Docker daemon restart containers?

Use a restart policy Similar to always , except that when the container is stopped (manually or otherwise), it is not restarted even after Docker daemon restarts. The following example starts a Redis container and configures it to always restart unless it is explicitly stopped or Docker is restarted.

How do I start the Docker daemon?

On MacOS go to the whale in the taskbar > Preferences > Daemon > Advanced. You can also start the Docker daemon manually and configure it using flags. This can be useful for troubleshooting problems. Many specific configuration options are discussed throughout the Docker documentation.


2 Answers

I wrote this little script to stop all the containers before docker is started. It requires to have jq installed.

for i in /var/lib/docker/containers/*/config.v2.json; do
  touch "$i.new" && getfacl -p "$i" | setfacl --set-file=- "$i.new"
  cat "$i" | jq -c '.State.Running = false' > "$i.new" && mv -f "$i.new" "$i"
done
like image 97
cdauth Avatar answered Nov 16 '22 01:11

cdauth


I think we need to verify the storage driver for docker that you are using. Devicemapper is known to have some issues similar to what you are describing. I would suggest moving to overlay2 as a storage driver.

If you are not running this on a prod system, you can try to do below steps to see if the daemon is coming up or not,

  1. Stop the daemon process
  2. Clean the docker home directory, default is /var/lib/docker/*
  3. You may not be able to remove everything, in that case safe bet is to stop docker from autostart ,systemctl disable docker and restart the system
  4. Once system is up, execute step-2 again and try to restart the daemon. Hopefully everything will come up.
like image 43
Shivam Singh Avatar answered Nov 16 '22 01:11

Shivam Singh