Home > Operation and Maintenance > Docker > How to start docker on boot

How to start docker on boot

PHPz
Release: 2023-04-18 14:43:32
Original
11092 people have browsed it

When using docker, it is often necessary to configure it to start at boot, so that the docker service can be automatically started after the server is restarted. This article will introduce how to start docker on boot.

The first step is to install docker

If docker has not been installed yet, you need to install docker first. I won’t go into details about the installation process here. You can search for relevant installation tutorials by yourself.

The second step is to create the systemd service file

On the Linux system, use systemd to manage the service. We need to create a systemd service file to define how docker is started.

Create the file /etc/systemd/system/docker.service and write the following content:

[Unit]
Description=Docker Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/dockerd
Restart=on-failure

[Install]
WantedBy=multi-user. target

The specific meaning of this file is as follows: The

  • [Unit] part defines some basic information of the service, the Description field is used to describe the service, and the After field is represented in network.target Start the service after booting. The
  • [Service] section defines how to start the docker service at boot. The Type field specifies the service type, simple is used here; the ExecStart field specifies the service startup command, which is dockerd; the Restart field specifies when the service fails. Perform a reboot. The
  • [Install] section specifies the installation method of the service, here it is installed under multi-user.target.

After creating the service file, use systemctl to reload the configuration file to make it effective:

systemctl daemon-reload

The third step is to set up the docker service to start Start

Set the docker service to start at boot, run the following command:

systemctl enable docker.service

This command will start the docker.service service when the system starts.

The fourth step is to verify whether the docker service is started successfully.

Run the following command to check whether the docker.service service is started:

systemctl is-enabled docker.service

If the command returns "enabled", it means that the docker.service service has been successfully started.

At this point, we have set the docker service to start at boot. In this way, the docker service will start automatically after the server is restarted. Improved production efficiency and convenience.

The above is the detailed content of How to start docker on boot. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template