Connecting docker client to remote Daemon

Milind Yadav
Nov 5 · 2 min read

This article is for beginners looking to explore remote docker set-up .

Here are the steps for centos7

Create two instances using AWS or any other service available

use : https://docs.aws.amazon.com/efs/latest/ug/gs-step-one-create-ec2-resources.html

connect to instance and install dockerCE — sudo su

yum install docker -y

once it is installed on both , rename the hosts as — docker-server and docker-client using below commands

hostnamectl set-hostname docker-server/docker-client

on the docker-server — make the following changes :

  1. Create directory — mkdir -p /etc/systemd/system/docker.service.d
  2. Create new file to store daemon options : vi /etc/systemd/system/docker.service.d/options.conf
  3. Put below contents in the options.conf created above :
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375

reload the system daemon : systemctl daemon-reload

start docker daemon : systemctl start docker or dockerd

In the docker-client machine set the below env variable :

export DOCKER_HOST=X.X.X.X (use host private/public or DNS address)

Once DOCKER_HOST is set , validate connection by running ,

Any docker commands , ex — docker ps or pull any image from docker hub .

ex-

the above image will be available on the docker-server.

Another example to validate is

on the client run : docker run -d — name container_1 milind0412/centos_git_httpd

once the container is up , use inspect as below :

docker inspect container_1 | grep -i workdir

try to cd to the path of workdir on client , it will not work , but same you will be able to execute on the remote .

References : https://nickjanetakis.com/blog/docker-tip-73-connecting-to-a-remote-docker-daemon

Milind Yadav

Written by

learning life everyday !! https://www.linkedin.com/in/milind-yadav-38630741/

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade