Methods to Stop Docker Daemon in Linux Systems: From systemctl to Manual Process Management

Nov 18, 2025 · Programming · 29 views · 7.8

Keywords: Docker daemon | systemctl | process management | Ubuntu | container runtime

Abstract: This article provides an in-depth exploration of various methods to stop the Docker daemon in Linux systems. Based on practical issues encountered in Ubuntu 16.04 environment, it focuses on analyzing why the systemctl stop docker command fails when Docker is manually started using sudo dockerd command. The article details systemd service management, process signal handling, and relationships between Docker architecture components, offering complete solutions and best practice recommendations. Through code examples and system analysis, it helps readers comprehensively understand Docker process management mechanisms.

Problem Background and Phenomenon Analysis

In Ubuntu 16.04 operating system, users attempt to stop Docker service using sudo systemctl stop docker command, but checking with ps ax | grep docker reveals that Docker-related processes are still running. Specific processes include:

11347 ?        Sl     0:00 containerd-shim 487e3784f983274131d37bde1641db657e76e41bdd056f43ef4ad5adc1bfc518 /var/run/docker/libcontainerd/487e3784f983274131d37bde1641db657e76e41bdd056f43ef4ad5adc1bfc518 runc
29914 ?        S      0:00 sudo dockerd -H gridsim1103:2376
29915 ?        Sl     4:45 dockerd -H gridsim1103:2376
29922 ?        Ssl    0:24 containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --runtime runc
30107 ?        Sl     1:01 /usr/bin/docker-proxy -proto tcp -host-ip 188.184.80.77 -host-port 8500 -container-ip 192.17.0.2 -container-port 8500
30139 ?        Sl     0:00 /usr/bin/docker-proxy -proto tcp -host-ip 188.184.80.77 -host-port 8400 -container-ip 192.17.0.2 -container-port 8400

Root Cause Analysis

From the process list, it's evident that the Docker daemon was manually started using sudo dockerd -H gridsim1103:2376 command, rather than through systemd service manager. This startup method causes the process to be uncontrolled by systemd, thus making the systemctl stop docker command ineffective.

Detailed Solutions

Immediately Stopping Currently Running Docker Processes

For manually started Docker processes, the most direct stopping method is sending termination signals to relevant processes:

# Find Docker-related process IDs
sudo ps aux | grep dockerd

# Use kill command to terminate processes
sudo kill -TERM 29915  # Replace with actual dockerd process ID

# If processes don't respond to TERM signal, use forced termination
sudo kill -KILL 29915

Correct Docker Service Management Approach

To avoid such issues, Docker service should be managed using systemd:

# Enable Docker service (auto-start on boot)
sudo systemctl enable docker

# Start Docker service
sudo systemctl start docker

# Stop Docker service
sudo systemctl stop docker

# Restart Docker service
sudo systemctl restart docker

# Check Docker service status
sudo systemctl status docker

Handling Socket Activation Mechanism

In some Docker installation configurations, socket activation mechanism may exist. When stopping docker.service, if warning message appears:

Warning: Stopping docker.service, but it can still be activated by: docker.socket

This indicates that docker.socket needs to be stopped simultaneously:

sudo systemctl stop docker.socket
sudo systemctl stop docker.service

Docker Architecture Component Analysis

From the process list, complete Docker runtime includes multiple components:

Best Practice Recommendations

Based on actual problems and solutions, the following best practices are proposed:

  1. Always use systemd to manage Docker service, avoid manually starting dockerd processes
  2. Before stopping Docker service, ensure all running containers are properly handled
  3. Regularly check Docker service status to ensure service management consistency
  4. In production environments, consider using container orchestration tools for finer process management

Supplementary Solution Comparison

Besides main solutions, other methods include:

Conclusion

Properly stopping Docker daemon requires understanding process startup methods and service management mechanisms. Through standardized Docker service management using systemd, various problems caused by manual process management can be avoided, ensuring system stability and maintainability.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.