简体   繁体   中英

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

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM