- A Ubuntu 18.04 installed on one of VM instance
- Install Docker
sudo mkdir -p /etc/systemd/system/docker.service.dsudo nano /etc/systemd/system/docker.service.d/options.conf[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375Now, reload the systemd daemon and restart the docker service:
# Reload the systemd daemon.
sudo systemctl daemon-reload
# Restart Docker.
sudo systemctl restart dockerThat’s going to let you continue to connect to the Docker daemon from within the VM thanks to -H unix://, but it also exposes the Docker Daemon with -H tcp://0.0.0.0:2375 so that anyone can connect to it over the non-encrypted port.
If you want to set DOCKER_HOST by default so it always connects remotely you can export it in your ~/.bashrc file. Here’s an example of that as a 1 liner:
echo "export DOCKER_HOST=tcp://X.X.X.X:2375" >> ~/.bashrc && source ~/.bashrcThat just adds the export line to your .bashrc file so it’s available every time you open your terminal. The source command reloads your bash configuration so it takes effect now.
You can test the configuration using a simple curl command, like the following:
curl <docker-host-ip>:2375/v1.38/containers/json If you have any running containers, you will receive a non-empty json response.
Congratulations, you’re now able to connect to a remote Docker daemon.