How to Expose Docker API on CentOS

Docker provides an API for interacting with the Docker daemon (called the Docker Engine API), as well as SDKs for Go and Python. The SDKs allow you to build and scale Docker apps and solutions quickly and easily. If Go or Python don’t work for you, you can use the Docker Engine API directly.

The Docker Engine API is a RESTful API accessed by an HTTP client such as wget or curl, or the HTTP library which is part of most modern programming languages.

  • The version of the Docker Engine API you should use depends upon the version of your Docker daemon and Docker client.
  • The Docker API is backward-compatible, so you do not need to update code that uses the API unless you need to take advantage of new features.

Expose-Docker-API

How to Expose Docker API on Centos 7

– Check your docker daemon service loaded the file.

# sudo systemctl status docker

[[email protected]]# sudo systemctl status docker
● docker.service – Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2018-01-30 12:55:41 PST; 1 day 3h ago
Docs: https://docs.docker.com

– Open that file using your favorite editor

# sudo vi /usr/lib/systemd/system/docker.service

– Add -H tcp://0.0.0.0:4243 this code where starts with ExecStart.  You can also expose different port and IPs.

ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:4243

– Save the modified file.

– Make sure the Docker service notices the modified configuration

# sudo systemctl daemon-reload

– Restart the Docker service

# sudo service docker restart

Test that the Docker API is accessible from outside.

# sudo curl <server-ip>:2375/images/json

It could be the security problem if we enabled the docker API via the public network and default port. Review the security concerns.