Connecting docker client to remote Daemon
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 :
- Create directory —
mkdir -p /etc/systemd/system/docker.service.d - Create new file to store daemon options :
vi /etc/systemd/system/docker.service.d/options.conf - Put below contents in the options.conf created above :
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375reload 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