Docker

Configure Docker Daemon Remote Access

Docker Daemon is one of the significant components of the Docker platform that is majorly utilized to connect the Docker client to the Docker server. It is responsible for executing Docker containers and managing Docker images on the host. By default, the dockerd is configured to accept requests from local clients or machines through a Unix socket.

However, there are scenarios where Docker users may need to configure remote access by enabling the Docker Daemon to accept requests from remote servers or hosts using IP addresses and ports.

In this blog, we will provide the technique to configure remote access for Docker Daemon.

How to Configure Remote Access For Docker Daemon?

Remote access for Docker Daemon is beneficial in different ways such as centralized control, easy management, collaboration, and easy monitoring and debugging. To configure Docker Daemon for remote access, go through the listed steps.

Step 1: Create “docker.service.d” Directory

First, create the directory named “docker.service.d” directory. This directory is usually used to configure daemon services. To create the directory, utilize the provided command:

sudo mkdir -p /etc/systemd/system/docker.service.d

Step 2: Edit Docker Service

Now, edit the “docker.service” file by utilizing the “systemctl edit docker.service” command as mentioned below:

sudo systemctl edit docker.service

Step 3: Configure Remote Access For Docker Daemon

Next, remove all the commented configurations and then add the mentioned line to the file. In the below configuration, replace the IP address with your IP address of the server and the preferred port:

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:2375

Step 4: Reload Docker Daemon

Reload the Docker Daemon by utilizing the “systemctl daemon-reload” command. This will apply the changes for Docker Daemon:

sudo systemctl daemon-reload

Step 5: Restart the Docker Service

Next, restart the Docker service through the given command:

sudo systemctl restart docker.service

Step 6: Verification

Next, verify whether the dockerd is configured for remote access or not using the “netstat” command:

sudo netstat -lntp | grep dockerd

The output shows that we have configured the Docker daemon for remote access:

Bonus Tip: Configure Docker Daemon Remote Access Through “daemon.json” File

To configure Docker Daemon remote access using the “daemon.json” file, utilize the provided procedure.

Note: On Windows “daemon.json” file is found in the “C:\Users\Dell\.docker” directory. We will provide the procedure to configure Docker Daemon remote access for Linux distribution. But the same procedure will be followed for Windows to add the configuration for Docker Daemon remote access in the “daemon.json” file.

Step 1: Open Docker Directory

First, navigate to the “etc/docker/” directory through the “cd” command:

cd /etc/docker/

View all files and directories “docker” directory using the “ls” command:

ls

Here, you can find the “daemon.json” file:

Step 2: Edit “daemon.json” File

Next, open the “daemon.json” file in a nano text editor with sudo user privilege:

sudo nano daemon.json

Add the following configurations to the file. After that, save the changes using “CTRL+O” and exit the nano editor through “CTRL+X”:

{

"hosts": ["unix:///var/run/docker.sock", "tcp://127.0.0.1:2375"]

}

Note: For Windows, navigate to the “C:\Users\Dell\.docker” directory, open the “daemon.json” file in any text editor, and add the above snippet into the file. After that, save the changes:

Step 3: Restart Docker Service

Restart the Docker services to apply changes using the following command:

sudo systemctl restart docker.service

That’s all about configuring Docker Daemon remote access.

Conclusion

To configure the Docker Daemon remote access, first, edit the “docker.service” file. Then, add the “ExecStart=/usr/bin/dockerd -H fd:// -H tcp://<IP-Address>:<Port>” line into the opened file and press the “CTRL+S” to save changes. Restart the Docker services and check if the dockerd is configured for remote access and not through the “sudo netstat -lntp | grep dockerd” command. The Docker Daemon remote access can also be configured through the “daemon.json” file. This post has provided the instruction to configure Docker Daemon remote access.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.