Docker starts automatically without booting
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.
- Prerequisites
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
- Edit the daemon.json file
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.
- Add systemd file
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:
- Description: The name of the service
- Documentation: The link to Docker’s official documentation
- After: A list of other services that need to be started when the service starts
- Wants: After some listed services are loaded, the service will be started after a period of delay
- Type: Service type
- ExecStart: Service startup command
- ExecReload: Service reload command
- EnvironmentFile: Environment variable file loading path
- Restart: How to restart the service
- RestartSec: The interval between restarting the service
- LimitNOFILE: The upper limit of the number of file descriptors that a process can open
- LimitNPROC: The upper limit of the number of threads that a process can create
- LimitCORE: The maximum memory limit that a process can use
- Reload systemd
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
- Enable systemd
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article details deploying applications to Docker Swarm, covering preparation, deployment steps, and security measures during the process.

The article explains Kubernetes' pods, deployments, and services, detailing their roles in managing containerized applications. It discusses how these components enhance scalability, stability, and communication within applications.(159 characters)

The article discusses scaling applications in Kubernetes using manual scaling, HPA, VPA, and Cluster Autoscaler, and provides best practices and tools for monitoring and automating scaling.

The article discusses implementing rolling updates in Docker Swarm to update services without downtime. It covers updating services, setting update parameters, monitoring progress, and ensuring smooth updates.

The article discusses managing Kubernetes deployments, focusing on creation, updates, scaling, monitoring, and automation using various tools and best practices.

Article discusses managing services in Docker Swarm, focusing on creation, scaling, monitoring, and updating without downtime.

Article discusses creating and managing Docker Swarm clusters, including setup, scaling services, and security best practices.

The article compares Docker Swarm and Kubernetes, focusing on their differences in architecture, ease of use, and ecosystem. Kubernetes is favored for large-scale deployments due to its scalability and advanced features, while Docker Swarm suits smal
