Atlantic.Net Blog

How to Set Up Remote Access to Docker Daemon

Hitesh Jethva
by Atlantic.Net (198posts) under Tutorials, VPS Hosting
0 Comments

If you are a system administrator and manage multiple Docker hosts, then you will need to connect to each Docker host and run a command to manage Docker. This can be a time-consuming process. This is where Docker daemon comes into the picture. Docker daemon allows you to connect to a remote docker host over TCP. This way, you can manage multiple Docker hosts from your local system without having to log in to each Docker host individually.

In this post, we will show you how to configure Docker daemon to manage the Docker host over TCP.

Prerequisites

  • A fresh Ubuntu 20.04 server on the Atlantic.Net Cloud Platform
  • A root password configured on your virtual private server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Ubuntu 20.04 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Install Docker CE

First, install all required dependencies with the following command:

apt-get install git apt-transport-https ca-certificates curl software-properties-common -y

Next, add the Docker GPG key with the following command:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add –

Next, add the Docker repository with the following command:

add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

Once the repository has been added, install Docker and Docker compose with the following command:

apt-get install docker-ce docker-compose -y

Once the installation is completed, verify the Docker version with the following command:

docker --version

You should see the following output:

Docker version 20.10.5, build 55c4c88

Step 3 – Configure Docker Daemon

First, you will need to create a directory to store the Docker daemon configuration file. You can create it with the following command:

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

Next, create a new file to store the daemon options.

nano /etc/systemd/system/docker.service.d/options.conf

Add the following lines:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375

Save and close the file, then reload the systemd daemon to apply the changes:

systemctl daemon-reload

Next, restart the Docker service to apply the changes:

systemctl restart docker

At this point, the Docker daemon is configured and listening on port 2375. You can check it with the following command:

ps aux | grep dockerd

You should get the following output:

root       48453  1.2  2.4 1005080 98520 ?       Ssl  00:58   0:00 /usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375
root       48775  0.0  0.0  12108   992 pts/0    S+   00:58   0:00 grep --color=auto dockerd

Step 4 – Configure Local System to Connect to the Docker Daemon

Before starting, make sure Docker and Docker compose are installed on your local system. Now, you will need to configure your local system to connect to the Docker daemon on the remote Docker host.

You can use a single one-liner to direct connect to the Docker daemon and run command on the remote Docker host. You can use the DOCKER_HOST variable to define the Docker daemon address.

For example, run the following command to run the docker info command on the remote Docker host:

DOCKER_HOST=tcp://remote-docker-host-ip:2375 docker info

Or

docker -H tcp://remote-docker-host-ip:2375 docker info

You should get the output of the docker info command as below:

Containers: 2
Images: 3
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: true
Execution Driver: 
Kernel Version: 4.18.0-193.6.3.el8_2.x86_64
Operating System: CentOS Linux 8 (Core)
CPUs: 2
Total Memory: 3.846 GiB
Name: centos8
ID: S56P:VPIW:CMGZ:GAFN:YZNG:22CE:OBY3:SKEW:JAMT:DLD4:FG5K:QXYR
Http Proxy: 
Https Proxy: 
No Proxy: 
Labels:

You can also run the docker-compose command on the remote host as shown below:

docker-compose -H tcp://remote-docker-host-ip:2375 --version

You can also set DOCKER_HOST variable in your .bashrc file. So you don’t need to specify every time when executing docker or docker-compose command.

You can set it with the following command:

echo "export DOCKER_HOST=tcp://remote-docker-host-ip:2375" >> ~/.bashrc

Next, activate the configuration with the following command:

source ~/.bashrc

Now, you can manage remote Docker host by just running the docker and docker-compose command locally.

For example, run the following command to check the Docker version on the remote host:

docker --version

Conclusion

In the above guide, you learned how to configure Docker daemon to connect the remote Docker host over TCP and manage it from the local system. I hope this will make your day-to-day Docker tasks much easier. Start using Docker daemon today on a VPS from Atlantic.Net!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources