How to enable Docker remote API
source link: https://rafaelnexus.com/tutorials/how-to-enable-docker-remote-api/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to enable Docker remote API
at Sun May 6, 2018 in
TL;DR
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.
Ubuntu 14.04
In /lib/systemd/system/docker.service
ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:4243
Ubuntu 16.04
/etc/default/docker or /etc/default/docker.io
DOCKER_OPTS="-H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock"
CentOS
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
Checking
Now to ensure the API is accessible, send a request to verify the version. These commands are being executed inside the Docker host.
curl http://localhost:4243/version
You should see something like this:
{"ApiVersion":"1.18","Arch":"amd64","GitCommit":"7c8fca2","GoVersion":"go1.2.1","KernelVersion":"3.13.0-145-generic","Os":"linux","Version":"1.6.2"}
And it is done!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK