Running Docker Remotely

Aman Pasi
4 min readJun 1, 2020

--

This article shows how you can run docker remotely.

What is Docker? or Containerization?
Docker is a set of platform as a service products that uses OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels.
In short you can think it as they(Containers) are lightweight Virtual Machine which are super-fast to boot.

You can install docker by following instruction in below links :
https://docs.docker.com/engine/install/

Following commands for CentOS or RHEL8 :
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

$ sudo yum install docker-ce docker-ce-cli containerd.io

Verify Docker Installation Using following command :
$ docker version

Docker Server Host OS

As you can see installation is done perfectly fine.
I want you to notice that docker has a Docker Client and a Docker Server.
When we use docker command it using Docker Client which acts as front-end to Docker Server. The Following Diagram show the architecture of Docker:

In order to perform remote execution we need to have another OS with Docker Client installed with some network connectivity between both OS. You can do this by installing docker above and then stopping the Docker Server using the following commands :
$ systemctl stop docker
$ docker version

You can see that only Docker Client is working and Docker Server has been stopped (Error : Cannot connect to docker daemon at …)/

By default in Docker Server can’t be accessed via outside network, in order to let Docker Server access outside network we need set tcp socket through which our Remote Docker Client will tell docker what to do.
We can do it by editing /lib/systemd/system/docker.service
In your case it may be at different location, you can find it by following command in Docker Host(where Docker Server is running) :
$ systemctl status docker

Edit/Add : -H tcp://0.0.0.0:4243 to
ExecStart=/usr/bin/dockerd -H fd://
(Note: You can choose any other port number if you want)
Your Service File Should Look Like this :
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:4243

Docker Server Host docker.service file

Now we have to restart the service:

$ systemctl daemon-reload
$ systemctl restart docker.service

Now our Docker Server is ready to take instruction from outside network
Now let’s setup Docker Client to send instruction to Docker Server Host.

By default if you run Docker Client it locally searches for docker server we can change this by setting an Environment variable DOCKER_HOST to IP:PORT of the Docker Server Host. Docker Client first check this variable before connecting the Docker Server Locally.
In my case the IP of my Docker Server Host OS is 192.168.31.207
Run the following commands to set environment variable:
$ export DOCKER_HOST=192.168.31.207:4243

This is How our setup has been done

Excellent you have successfully setup the Remote Docker Execution, it time to run our docker client from remote.

Hooray! Its working…
now you can run any command from Remote Docker Client and the containers will run on Docker Server Host.

Use case :
Why use docker remotely if we can make kubernetes cluster to do the same?
Ans. We use remote docker execution to do what kubernetes can’t do and that is to build image.
What if a Developer wants to build an image of a Web-Server automatically on server rather than its own laptop by pushing Website data and Dockerfile , in this case we can use remote docker execution.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Aman Pasi
Aman Pasi

No responses yet

Write a response