Home Operation and Maintenance Docker Docker starts automatically without booting

Docker starts automatically without booting

May 13, 2023 pm 01:05 PM

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.

  1. 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
Copy after login
  1. 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
Copy after login

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"
    }
}
Copy after login

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.

  1. 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
Copy after login

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
Copy after login

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
  1. 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
Copy after login
  1. 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
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I deploy applications to a Docker Swarm cluster? How do I deploy applications to a Docker Swarm cluster? Mar 17, 2025 pm 04:20 PM

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

What are Kubernetes pods, deployments, and services? What are Kubernetes pods, deployments, and services? Mar 17, 2025 pm 04:25 PM

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)

How do I scale applications in Kubernetes? How do I scale applications in Kubernetes? Mar 17, 2025 pm 04:28 PM

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.

How do I implement rolling updates in Docker Swarm? How do I implement rolling updates in Docker Swarm? Mar 17, 2025 pm 04:23 PM

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.

How do I manage deployments in Kubernetes? How do I manage deployments in Kubernetes? Mar 17, 2025 pm 04:27 PM

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

How do I manage services in Docker Swarm? How do I manage services in Docker Swarm? Mar 17, 2025 pm 04:22 PM

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

How do I create a Docker Swarm cluster? How do I create a Docker Swarm cluster? Mar 17, 2025 pm 04:19 PM

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

How does Docker Swarm differ from Kubernetes? How does Docker Swarm differ from Kubernetes? Mar 17, 2025 pm 04:18 PM

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

See all articles