How to Stop Docker in Linux?

On Linux, Docker is a software utility utilized for creating, testing, and deploying applications. It contains standardized units known as docker containers with everything associated with software packages. It is supported by Linux and its distributions including CentOS, Ubuntu, Linux Mint, etc. Its services can be managed in different ways as starting, stopping, restarting, and reloading as per requirements.

This guide illustrates the possible methods to stop Docker under Linux:

  • Using the “systemctl” Command 
  • Using the “service” Command 

Method 1: Using the “systemctl” Command

The “systemctl” command line tool is responsible for managing and controlling the systemd initialization system and the service managers. It provides the list of supported flags to perform this task based on their names i.e., stop, start, enable, disable, restart, and reload.

Stop Docker

The “systemctl” command uses the “stop” option to stop the “Docker” services having the root user rights i.e. “sudo” if the normal user is logged in:

$ sudo systemctl stop docker.socket

The “docker” has been stopped alongside its “socket” running service. 

Verify Docker Status

For verification purposes, use the “status” flag of the “systemctl” that shows the current status of the “docker” services:

$ sudo systemctl status docker.socket

The output confirms that the docker.socket has been stopped temporarily i.e. “inactive(dead)” state. It will start automatically after the system reboot.

Disable Docker (Permanently)

To stop the docker services permanently use the “disable” systemctl command as it will not start again at the reboot time:

$ sudo systemctl disable docker

At this time the “docker” has been stopped permanently.

Execute the “status” command again to check the “docker” current status:

$ sudo systemctl status docker

The “docker” application has been stopped i.e., “disabled”.

Method 2: Using the “service” Command 

The “service” command line utility is also beneficial to temporarily start and stop the system services. It works on the SystemV init script that is placed in the /etc/init.d directory. This section carries out its practical implementation to stop the docker services:

Stop Docker

Specify the “stop” option at the end of the “service” command to stop “Docker” until the system reboots with “sudo” support in this way:

$ sudo service docker stop

The “docker” service has been stopped instantly.

Confirm Docker Status

The “service” command also provides the “status” option to confirm the “docker” services status:

$ sudo service docker status

The output is similar to the “systemctl” command and has stooped the “Docker” services.

Bonus Tip: Start Docker

To start the “docker” service again use the “start” option with the “service” command:

$ sudo service docker start

The “docker” service has been started again.

Conclusion

Linux provides the “systemctl” and “service” command line utilities with the “stop” option to stop the “Docker” services quickly. The “systemctl” stops the docker services temporarily with the “stop” and permanently with the “disable” option. However, the “service” tool stops the docker system temporarily before the system reboots.

This post has covered all possible methods to stop Docker under Linux.