Table of Contents
Enable Docker Remote REST API on Docker Host in Ubuntu
Introduction
Docker provides remote REST API which is beneficial if you want to connect to a remote docker host. Few of the functions which you can achieve using Docker REST API over a simple browser are
- Create and Manage Containers
- Get low-level information about a container
- Get Container Logs
- Start/Stop container
- Kill a container
My remote docker host was an Ubuntu Virtual Image on Microsoft Azure.
In this tutorial, I will show you
- What didn’t worked?
- What really worked.
Things that didn’t worked
Over the internet, most of the people have suggested editing DOCKER_OPTS variable.
- I changed DOCKER_OPTS in the /etc/default/docker file but it didn’t have any effect
- Then I tried changing DOCKER_OPTS in the file /etc/init/docker.conf but again no success.
What really worked for me to enable docker remote API on docker host
- Navigate to /lib/system/system in your terminal and open docker.service file123vi /lib/systemd/system/docker.service
- Find the line which starts with ExecStart and adds -H=tcp://0.0.0.0:2375 to make it look like123ExecStart=/usr/bin/docker daemon -H=fd:// -H=tcp://0.0.0.0:2375
- Save the Modified File
- Reload the docker daemon123systemctl daemon-reload
- Restart the container123sudo service docker restart
- Test if it is working by using this command, if everything is fine below command should return a JSON123curl http://localhost:2375/images/json
- To test remotely, use the PC name or IP address of Docker Host
Please note that docker standard TLS port is 2376 and 2375 are the standard unencrypted port. As we have defined 0.0.0.0, which defines an open interface for everyone. Anyone with network access to this port will have full root access on the host. I have restricted the access by creating an access-controlled list in Azure so please follow some similar mechanism to restrict access
Or use docker.
docker run -d \
–name sherpa \
-v /var/run/docker.sock:/tmp/docker.sock \
-p 2375:4550 \
djenriquez/sherpa –allow
This works for packages installed via apt, but the config files are different with snap. Where can the -H be set when docker is installed via snap?