The default installation for Docker on Ubuntu server (16.04) configures the daemon (service) to listen on a local socket. But what if you want to access your Docker daemon remotely, from another box, If you are using the default configuration, you would need to open a Secure Shell to the server, and access Docker that way. But there is a way to setup Docker to allow remote access.
First, lets verify that Docker is only working with a local socket. On the server, run from this command line:
ls -l /run
The results show have an entry with the docker.sock entry like this:
And you can check that the daemon is not listening on any ports on your system by running this command:
sudo netstat -tlp
No Docker application should be listed in the results.
- Now change to /etc/default.
- As root, open the docker file in the folder with a text editor:
- Find the line that starts #DOCKER_OPTS= and add a new line below it.
- The new line should be:
substitute your server’s IP address for 192.168.0.22. The port specified :2375 is the conventional one used for unencrypted communications to the docker daemon. Use :2376 for an encrypted port.
- Save the file and exit.
- Restart your Docker service:
sudo service docker restart
- Verify that Docker is now listening on the IP address specified, by rerunning this command:
sudo netstat -tlp
- The results should show that Docker is indeed listening on the specified port
- Docker is now setup to listen for remote communications. To test it, form your Docker server, run this command, again substituting your server’s IP address:
docker -H tcp://192.168.0.22:2375 version
- You should see results similar to this:
- Docker is now responding to requests on the address and port you specified! When accessing your Docker machine remotely, be careful of mixing release candidate clients with stable Docker daemons. They don’t play nice together.