CentOS7下如何启动Docker守护进程而不启动自动重启容器?
Absolutely, Docker has a built-in way to start the daemon without launching any containers—perfect for your scenario where a misbehaving auto-restart container is blocking the daemon from fully starting up. Here are two reliable methods to resolve this:
Method 1: Manual Daemon Start with --no-startup-containers
This is the cleanest and most direct approach:
Kill stuck Docker processes
First, stop the hung Docker service and any lingering daemon processes:systemctl stop docker # If the daemon is still running, locate and terminate it ps aux | grep dockerd kill -9 <PID_of_dockerd>Launch the daemon without container startup
Run the Docker daemon directly with the--no-startup-containersflag to skip launching all containers (even those set to auto-restart):dockerd --no-startup-containersThe daemon will fully start up without attempting to load any containers, letting you access the Docker CLI normally.
Fix the problematic container
Open a new terminal window (keep the manual dockerd process running), then:- List all containers to identify the one causing issues:
docker ps -a - Disable auto-restart for the problematic container to prevent future blocks:
docker update --restart=no <container_name_or_id>
- List all containers to identify the one causing issues:
Restart Docker normally
Stop the manual dockerd process (press Ctrl+C in its terminal), then start the service as usual:systemctl start docker
Method 2: Temporarily Hide Container Metadata (Fallback)
If the flag method doesn’t work for some reason, you can temporarily move container configs to force Docker to start empty:
Stop Docker and move the containers directory
systemctl stop docker mv /var/lib/docker/containers /var/lib/docker/containers.bakStart Docker normally
systemctl start dockerDocker will start without any containers since it can’t find the metadata files.
Restore and resolve the issue
Stop Docker again, move the directory back, then use the--no-startup-containersflag to fix the problematic container:systemctl stop docker mv /var/lib/docker/containers.bak /var/lib/docker/containers dockerd --no-startup-containers # Run docker update --restart=no <container_id> as before
Note: Always back up the
/var/lib/dockerdirectory before modifying it to avoid accidental data loss.
内容的提问来源于stack exchange,提问作者Mad Scientist

