How To Enable Docker Remote API

You will need Docker remote API in various situations. Let’s say you are running the docker host on a remote server and you want to connect to it from your laptop. For this scenario, you can use the remote API and connect to it using REST API’s as the docker engine accepts REST requests.

One more use case is that let’s say you have an application and you want to get the details of the containers in docker host. For this, you can use the remote API feature.

Enable Docker Remote API

All the docker configurations are present in the file/lib/systemd/system/docker.service. In that file, there is an ExecStart parameter.

Open the file/lib/systemd/system/docker.service, search for ExecStart and add values as shown below.

For Ubuntu,

For Centos,

The above command will bind the docker engine server to the Unix socket as well as TCP port 4243. “0.0.0.0” means docker engine accepts connections from all IP addresses.

You Might Like:

  1. Docker Mastery: The Complete Toolset From a Docker Captain
  2. Learn DevOps: The Complete Kubernetes Course

Now for all the changes to take place, you need to restart the daemon and Docker service. Execute the following commands to do that.

Now, remote API is enabled on your docker host. To test this, there are few ways.

Test using curl

Get the IP address of your docker host where you enabled remote API and execute the following command from any terminal which supports curl. You can test with localhost as well.

Note: replace the IP with your Docker host IP or localhost as shown below.

The above command will output all the images in your docker host in JSON format.

Test using REST client

You can test the API using REST client like Postman. If you use the following URL in your REST client, you will get the JSON output in a prettified manner as shown in the image below.

enable docker remote API

In this tutorial, you learned to enable Docker remote API. For better security, you can use certificated with the REST requests. That we will cover in another detailed post If you face any issues with this setup, let us know in the comments section.

Related

There are few situations in which you might want to get into the container shell or may be run a single command in a…

Read more
docker cheat sheet - beginners guide

Docker has many commands to remember. If you are starting up with docker, We are pretty sure that you will have a hard…

Read more

Internet is huge! Help us find great content

Newsletter

Never miss a thing! Sign up for our newsletter to stay updated.

About

The Best Tutorials & Tips to Speedup Your DevOps Workflow.

Created by Bibin Wilson.

All Udemy Course For $9.99