WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud
  • Tanzu
    • Application Modernization
    • Tanzu services
    • Tanzu Community Edition
    • Tanzu Kubernetes Grid
    • vSphere with Tanzu
  • Home Lab
  • Nested Virtualization
  • Apple
You are here: Home / Automation / Quick Tip - How to enable Docker Remote API?

Quick Tip - How to enable Docker Remote API?

07.27.2014 by William Lam // 18 Comments

I have been playing around with Docker lately in my home lab and have primarily been using the Docker CLI. While going through the documentation, I found that Docker also provides a nice remote REST API which by default, seems to be disabled. I was searching online but could not find any tutorials that provides clear instructions on how to enable the remote API for an Ubuntu Virtual Machine that I recently built to run Docker.

With some trial and error, I was able to finally figure out what was needed and figure I would document this for myself and for anyone else who maybe interested.

If you have Docker running on an Ubuntu (14.04 is what I'm using), you will need to edit /etc/init/docker.conf and update the DOCKER_OPTS variable to the following:

DOCKER_OPTS='-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock'

This will have Docker bind to port 4243 which will be used by the Docker Remote API. One you have saved your changes, you will need to restart the Docker process by running the following command:

service docker restart

To test that the Docker Remote API has been properly enabled, we will list the Images currently in Docker (this assumes you have at least pulled down one image from the Docker Hub Registry).

In my environment, I have the following Docker Images:

enable-docker-remote-api-1
Using my Firefox browser and the RESTClient plugin, I can perform a GET operation on the following URL: http://172.30.0.199:4243/images/json as described in the Docker Remote API.

enable-docker-remote-api-2
As we can see from the screenshot above, we see the same Images displayed from the remote API. You can also easily test this by using cURL on the command-line by running the following command:

curl -X GET http://172.30.0.199:4243/images/json

If you are running CoreOS (which I also have running in my vSphere environment), you can enable the Docker remote API by following the documentation here. Hopefully this will be helpful for anyone looking to enable the Remote API but not able to find the exact steps.

More from my site

  • Configuring Github Actions self-hosted runners on PhotonOS 
  • Project USB to SDDC - Part 3
  • Quick Tip - Creating a multiline Dockerfile using heredoc w/variable substitution
  • Easily try out vSAN 6.6 Encryption feature using KMIP Docker Container
  • Project USB to SDDC - Part 2

Categories // Automation, Docker Tags // Docker, docker.conf, remote api

Comments

  1. Jay says

    09/13/2014 at 5:46 pm

    Very helpful! Thank you!

    Reply
  2. m says

    12/17/2014 at 8:57 pm

    The service command does not exist on my docker installation?

    Reply
    • ArtworkAD (@artwork_ad) says

      01/06/2015 at 4:34 pm

      You have to put it in /etc/default/docker

      Reply
  3. Sigmund Lundgren (@sigmundl) says

    02/24/2015 at 3:16 pm

    Why don't you use the default 2375 port?

    Reply
  4. Vishal Biyani (@vishal_biyani) says

    06/30/2015 at 12:31 am

    Thank you! This helped immensely!

    Reply
  5. matheeeny says

    07/15/2015 at 2:52 pm

    Why not put this in /etc/defaults/docker?

    Reply
    • stampycode says

      02/12/2016 at 3:29 am

      because the config file is at `/etc/default/docker` (not "defaults") 😀

      Reply
  6. ANVIKA says

    05/28/2016 at 9:24 am

    Please describe the same for windows !! I really need it 🙂 thanks in advance.

    Reply
  7. Ryan Schroeder says

    06/07/2016 at 11:48 am

    Was wondering how to do this; especially the -H 0.0.0.0:55555 for exposing the docker remote api unsecured, without the fancy authentication stuff, thanks!

    Reply
  8. Oliver Weise says

    08/18/2016 at 6:00 am

    Thanks ,that put me in the right direction. However since Ubuntu 16.04 with its systemd docker daemon the /etc/default/docker is no longer effective. Instead you need to create a systemd dropin file.

    I placed such a file under: /etc/systemd/system/docker.service.d/remote-api.conf

    With the contents:

    [Service]
    ExecStart=
    ExecStart=/usr/bin/dockerd -H tcp://127.0.0.1:2376 -H unix:///var/run/docker.sock

    (Yes, the double ExecStart is necessary)

    After that run:
    sudo systemctl daemon-reload // reloading daemon definitions
    sudo systemctl restart docker

    Reply
    • Bryan Robbins says

      11/06/2016 at 4:17 pm

      +1 for this. The same works for any systemd-based system (such as RHEL/CentOS 7).

      Also shown here: recommend binding on 127.0.0.1 instead of 0.0.0.0, unless you have a good reason!

      Cheers.

      Reply
    • John says

      12/05/2016 at 1:53 pm

      +1

      Reply
  9. Justin Lee says

    08/18/2016 at 8:26 am

    Thank you for this very helpful documentation!

    Reply
  10. DJ Enriquez (@denriquezjr) says

    10/18/2016 at 11:07 pm

    Instead of changing the Docker daemon configuration and restarting it, you can run Sherpa, a container that opens up a port to the unix socket via reverse-proxy. Check it out: https://hub.docker.com/r/djenriquez/sherpa/

    Reply
  11. gpk09 says

    12/14/2016 at 4:47 am

    Really this article has helped me, thanks for great share

    Reply
  12. Raj says

    02/03/2017 at 11:02 am

    Thats an awesome article .. Thank you

    Reply
  13. Pankaj says

    06/12/2017 at 1:22 am

    This doesn't work on 16.04. However, its on similar lines. Please following instructions at https://www.ivankrizsan.se/2016/05/18/enabling-docker-remote-api-on-ubuntu-16-04/ for the same.

    Reply
  14. Navaneetha Kandethodi says

    12/19/2017 at 7:22 pm

    Now the modification in /etc/defaults/docker does not work. Please refer to following working solution
    http://www.littlebigextra.com/how-to-enable-remote-rest-api-on-docker-host/

    Reply

Thanks for the comment! Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Author

William Lam is a Senior Staff Solution Architect working in the VMware Cloud team within the Cloud Infrastructure Business Group (CIBG) at VMware. He focuses on Cloud Native technologies, Automation, Integration and Operation for the VMware Cloud based Software Defined Datacenters (SDDC)

Connect

  • Email
  • GitHub
  • LinkedIn
  • RSS
  • Twitter
  • Vimeo

Recent

  • Changing the default HTTP(s) Reverse Proxy Ports on ESXi 8.0 03/22/2023
  • Quick Tip - How to download ESXi ISO image for all releases including patch updates? 03/15/2023
  • SSD with multiple NVMe namespaces for VMware Homelab 03/14/2023
  • Is my vSphere Cluster managed by vSphere Lifecycle Manager (vLCM) as a Desired Image or Baseline? 03/10/2023
  • Interesting VMware Homelab Kits for 2023 03/08/2023

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2023

 

Loading Comments...