How to exit the docker daemon

PHPz
Release: 2023-04-18 09:08:32
Original
1306 people have browsed it

The Docker daemon is the core component responsible for running and managing Docker containers. However, there may be times when it is necessary to exit the Docker daemon, such as when the system is restarted after a reboot. This article will introduce how to exit the Docker daemon process.

1. How to exit the docker daemon process

When the Docker daemon process starts, you can specify the way the daemon process exits through parameters. The following are commonly used exit methods:

  1. SIGTERM: Sending a SIGTERM signal allows the Docker daemon to exit gracefully, stop running containers, and save the status and data of the container and image. Exiting the Docker daemon in this way ensures data integrity.
  2. SIGINT: Sending a SIGINT signal allows the Docker daemon to exit gracefully, but if there are running containers, they may be forced to stop and data may be lost.
  3. SIGKILL: Sending a SIGKILL signal can force the Docker daemon to exit, which will stop all running containers and will not save the status and data of the containers and images. Exiting the Docker daemon using this method may result in data loss.

2. Implementation of exiting the Docker daemon process

There are two ways to exit the Docker daemon process:

  1. Use the docker command

Use the docker command to exit the Docker daemon. First, you need to check the process number of the Docker daemon, and then use the kill command to send a signal to exit the Docker daemon, as shown below:

# 查看Docker守护进程的进程号
$ ps aux | grep dockerd
root      1139  0.0  0.2 139168 41496 ?        Ssl  11:21   0:00 dockerd -H unix:///var/run/docker.sock

# 发送SIGTERM信号退出Docker守护进程
$ kill -s SIGTERM 1139
Copy after login
  1. Modify the Docker daemon startup parameters

When the Docker daemon starts, you can specify the exit method through parameters. If no exit method is specified, SIGTERM is used by default. You can change the exit method by modifying the startup parameters, as shown below:

  1. Edit the service file of the Docker daemon process
$ sudo vim /usr/lib/systemd/system/docker.service
Copy after login
  1. Add ExecStop in the Service section Line
[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/dockerd --shutdown-timeout 30 # 添加此行
KillMode=process
Copy after login
  1. Restart the Docker daemon
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker.service
Copy after login

3. Summary

The Docker daemon is one of the core components of Docker. Exit Docker The daemon process can use the docker command or modify the Docker daemon startup parameters. When exiting the Docker daemon, you need to choose an appropriate exit method to ensure data integrity.

The above is the detailed content of How to exit the docker daemon. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!