How to enable Docker remote API
WHAT: Enable Dockers API to allow Docker to be controlled remotely.
HOW: Exposing Docker’s TCP port.
Docker Engine API allows you to do basically everything you do from the command line but from an API interface which is crucial in many scenarios, especially for automation and orchestration.
1. Expose Docker’s TCP port
It might differ from distro to distro, so in case it is not the same as one of these examples, try to find similar configuration parameter in the specific configuration file from your distro.
ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:4243
/etc/default/docker or /etc/default/docker.io
DOCKER_OPTS="-H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock"
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
Restart the services
You will need to restart the services to check the changes.
sudo systemctl daemon-reload
sudo service docker restart
If you get something like this:
systemctl: command not found
You need to install systemd package.
sudo apt-get install systemd -y
Now to ensure the API is accessible, send a request to verify the version.
These commands are being executed inside the Docker host.
You should see something like this:
And it is done!