How to start docker daemon on Mac OS

How to start docker daemon on Mac OS

How to start docker daemon on Mac OS

To start a daemon on MacOS, you must create a launch daemon configuration file and use the launchctl command to load and start the daemon.

  1. Create a launch daemon configuration file: A launch daemon configuration file is a property list (plist) file that contains the information needed to start and manage a daemon on MacOS. The file must be saved in the /Library/LaunchDaemons directory and have a .plist extension.

    For example, to create a launch daemon configuration file for the Docker daemon, you could create a file called com.docker.vmnetd.plist in the /Library/LaunchDaemons directory with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.docker.vmnetd</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/dockerd</string>
        <string>-H</string>
        <string>tcp://127.0.0.1:2375</string>
        <string>-H</string>
        <string>unix:///var/run/docker.sock</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>
  1. This file specifies the program (/usr/local/bin/dockerd) and the arguments (-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock) that should be used to start the Docker daemon. It also specifies that the daemon should be started when the system loads and that it should be kept running even if no users are logged in.

  2. Load the daemon: Once you have created the launch daemon configuration file, you can use the launchctl command to load the daemon and start it. For example, to load the Docker daemon, you could run the following command:

sudo launchctl load /Library/LaunchDaemons/com.docker.vmnetd.plist

This will load the com.docker.vmnetd.plist the file and start the Docker daemon.

Cannot connect to the docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

This error usually appears when Docker is not running on your Mac.
You can verify that the daemon is running by using the ps command to list the processes that are currently running on your system and filtering the output to show only the processes with "docker" in the name:

ps aux | grep docker

If the Docker daemon is running, you should see a line of output similar to this:

root         9   0.0  0.0  2432784    584   ??  Ss    5:15PM   0:00.03 /usr/local/bin/dockerd
  1. (Optional) Enable the daemon to start automatically at boot time: By default, a launch daemon will only be loaded and started when the launchctl load command is run. If you want the daemon to be permanently available on your system and to start automatically at boot time, you will need to enable it using the launchctl enable command. For example, to enable the Docker daemon to start automatically at boot time, you could run the following command:
sudo launchctl enable system/com.docker.vmnetd

This will enable the com.docker.vmnetd daemon to start automatically when the system boots. You can verify that the daemon is enabled by using the launchctl command to list the enabled daemons:

sudo launchctl list | grep docker

This should show you a line of output similar to this:

-   0   com.docker.vmnetd

This indicates that the com.docker.vmnetd daemon is enabled and will be started automatically at boot time.

Once you have completed these steps, the daemon will run on your system and be available to run applications or perform other tasks as needed.

Stop the Docker daemon on macOS

To stop the Docker daemon on macOS, you can use the launchctl command to unload the launch daemon configuration file that was used to start the daemon. For example, to stop the Docker daemon, you could run the following command:

sudo launchctl unload /Library/LaunchDaemons/com.docker.vmnetd.plist

This will unload the com.docker.vmnetd.plist file and stop the Docker daemon. You can verify that the daemon has been stopped by using the ps command to list the processes that are currently running on your system, and filtering the output to show only the processes with "docker" in the name:

ps aux | grep docker

If the Docker daemon is not running, you should not see any output from this command.

Alternatively, you can use the launchctl command to stop the Docker daemon directly, without unloading the launch daemon configuration file. To do this, you can run the following command:

sudo launchctl stop system/com.docker.vmnetd

This will stop the com.docker.vmnetd daemon, which will in turn stop the Docker daemon. You can verify that the daemon has been stopped by using the launchctl command to list the enabled daemons:

sudo launchctl list | grep docker

This should not show any output, indicating that the com.docker.vmnetd daemon is not currently running.

Related articles

Ruslan Osipov
Written by author: Ruslan Osipov