I tried to find instructions on how to enable the Docker remote API when running Docker in Ubuntu 16.04, but none of the instructions I came across managed to take me all the way, so here are a few short notes on how I managed to accomplish this:
- Edit the file /lib/systemd/system/docker.service
I used the vi editor:sudo vi /lib/systemd/system/docker.service
- Modify the line that starts with ExecStart to look like this:
ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:4243
Where my addition is the “-H tcp://0.0.0.0:4243” part.
- Save the modified file.
- Make sure the Docker service notices the modified configuration:
systemctl daemon-reload
- Restart the Docker service:
sudo service docker restart
- Test that the Docker API is indeed accessible:
curl http://localhost:4243/version
You should see output similar to this as the result:
{"Version":"1.11.0","ApiVersion":"1.23","GitCommit":"4dc5990","GoVersion":"go1.5.4","Os":"linux","Arch":"amd64","KernelVersion":"4.4.0-22-generic","BuildTime":"2016-04-13T18:38:59.968579007+00:00"}
- To access the Docker API from another computer, use the IP address of the Ubuntu computer found at either wlan0 or eth0, depending on whether you use wifi or ethernet network connection.
To learn the IP addresses of the different interfaces, use the ifconfig command in a terminal window. In my case it is 192.168.1.68.
Finally, this screenshot shows how to set up access to the Ubuntu computer’s Docker API from inside IntelliJ IDEA with the Docker plug-in installed. I only modified the API URL and left the path to the certificates folder unchanged.
Happy coding!
Thanks a lot, this helped me out!
However, on my system (also Ubuntu 16.04) I had to add the following option to be able to execute docker commands from shell:
-H unix:///var/run/docker.sock
Thus, my config line in /lib/systemd/system/docker.service reads as follows:
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
Best,
Philipp
Thanks for the input!
Thanks dude!
Hi All,
Just a quick note you can also edit the DOCKER_OPTs in /etc/init/docker.conf. Simple change the line to look like:
DOCKER_OPTS=’-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock’
Thanks
Stefan
This file only exist in few of the OS for example it dose not exits on CentOS , so we have add it in
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
It did not work for me on Ubuntu 16.04.2 LTS
Yes it worked , “/usr/bin/dockerd” not “/usr/bin/docker daemon ” in case of ubuntu 16.04
@Bibekananda Mantry – thanks – your solution worked for me too.
Instead of changing the Docker daemon configuration and having to restart the service, you can run Sherpa, a container that opens a port to the remote API without changing configuration. Check out the repo here: https://hub.docker.com/r/djenriquez/sherpa/
Thanks for the input!
A comment to the above: Sherpa is a Docker image containing Nginx.
Not sure if this is a change but under “Ubuntu 16.04.1 LTS” (from lsb_release -d) I got a warning when restarting Docker:
Warning: docker.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.
If I didn’t do this Docker didn’t pick up the change to the docker.service file.
Hi Scott!
Yes, you are correct – I have seen this before but it seems I forgot to include that step. Post is now updated!
Thanks!
http://serverfault.com/questions/843296/how-do-i-expose-the-docker-api-over-tcp/843332#843332
Thanks a lot. I sifted through a dozen guides before managing to fix my issue.
Worked like a charm for me, thanks a lot!
+1
Workerd after add proper DOCKER_OPTS to /etc/init/docker.conf
Man… there are a few articles online on how to enable remote docker access. I always need to find this particular one, cause none of the other ones work. 😀
After trying out many other articles and suggestions, I finally arrived at your article and that did the trick for me on Ubuntu Xenial and Docker 17.06. Thanks very much for sharing!
kind regards
Lucas
You should be adding this in /etc/default/docker
Pingback: 通过暴露的docker.sock文件接管容器 – NEWS.ALL
Pingback: pycharm can’t complete remote interpreter setup for Docker – Config9.com