Docker is one of the most popular containerization software currently, which can help developers create and run applications more conveniently. But sometimes, you may encounter a problem: Docker will not start automatically after you start your computer. If you want Docker to start automatically, let's take a look at how to set it up.
Before setting up, you first need to confirm whether your Docker has systemd and daemon.json files installed. Both files are required as they will help Docker start automatically at boot.
If they are not installed on your system, you can use the following command to install them:
sudo apt-get update sudo apt-get install systemd
Enable Docker On systems, you need to edit the /etc/docker/daemon.json file. If the file does not exist, you can create it using the following command:
sudo nano /etc/docker/daemon.json
Then, add the following code to the file:
{ "default-address-pools": [ {"base":"172.0.0.0/8","size":16}, {"base":"192.168.0.0/16","size":24} ], "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "3" } }
This code snippet contains some Docker configuration information. It also contains a default address pool that will be used to assign IP addresses to Docker containers. You can modify it as needed.
Next, you need to create a systemd file named docker.service and add it to the /etc/systemd/system/ directory middle.
Create a new file using the following command:
sudo nano /etc/systemd/system/docker.service
Add the following code to the file:
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target sshd.service Wants=network-online.target [Service] Type=notify ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ExecReload=/bin/kill -s HUP $MAINPID EnvironmentFile=-/run/flannel/docker Restart=always RestartSec=3 LimitNOFILE=1048576 LimitNPROC=infinity LimitCORE=infinity [Install] WantedBy=multi-user.target
This file will tell systemd how to start Docker and configure some options, as follows:
After adding the systemd file to the /etc/systemd/system/ directory, you need to reload the systemd process for the configuration to take effect. You can use the following command to reload systemd.
sudo systemctl daemon-reload
The next step is to enable the Docker service to start automatically. You can enable systemd using the following command.
sudo systemctl enable docker.service
This command will automatically start Docker when booting.
Finally
Now, you have learned how to automatically start the Docker service when the system starts. If you encounter other Docker problems, you can refer to the official Docker documentation or ask for help in the community.
The above is the detailed content of Docker starts automatically without booting. For more information, please follow other related articles on the PHP Chinese website!