Enabling and accessing Docker Engine API on a remote docker host on Ubuntu

What is Docker Engine API ?

Docker has become one of the most popular technologies used all around the world today. Docker engine is the portion of a docker installation which takes care of the all the docker features. But when we are trying to automate the processes which uses the docker features such as “deploying an app via Jenkins” we need a way to access the docker engine via a scripts and run docker commands. Docker API helps the developers to access the docker engine through their scripts.

When the Docker Host is in a remote machine, we need a way to access the docker engine API . For accomplishing this task, we can open up a TCP port which allows us to connect with the remote docker host

Enabling Docker Remote API ( Earlier versions of Ubuntu)

After a successful docker installation we have to verify that the docker host is running. You can verify that by running

Then we have to add the tcp port details to the file. For that first open a file in named by running

This needs nano editor to be installed before.If the above command fails you can use some other editor such as orrun the below command for installing nano editor

Then add the below line at the end of the file

You have to replacewith the port number like below

Then we have to restart the docker host for the changes to take effect. Do that by typing

Then docker has to be accessed via the tcp port you gave. Verify that you can access the docker host through the specified docker port by running the command

Replace <port> with the port you specified. In my case it is

Enabling Docker Remote API ( for Ubuntu 16.04)

In Ubuntu 16.04 , above procedure doesn’t have any effect on docker and is not able to open up the tcp port for docker host. For that open up the /lib/systemd/system/docker.service file by running the command. (For this command , you need nano or you can use an editor like vi as I mentioned above)

Then you have to update the file like this,

You have to replace <port> with your desired port. In my case it’s like this,

now save your changes with and exit from the editor using

Then restart the docker service runningg below commands

For verifying whether the port is working, you can either use the method I mentioned earlier for earlier versions of ubuntu or run the following command

This should return a json with all the images in the docker

Enjoy !!!!

Gopher 💻 Cloud ☁️ Distributed Computing 🖥

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store