I’m trying to set up my local Docker CLI to communicate with a remote Docker Engine running on a DigitalOcean Droplet. Basically, I don’t have much resources on my local machine so I need to run some builds and runs on a remote Droplet.
I’d like to understand:
I’ve looked at the Docker documentation, but I’d love to hear from the community about practical tips, common pitfalls, and real-world use cases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hey there!
One way of of doing this is, uou can connect your local Docker CLI to a remote Docker Engine by setting the DOCKER_HOST
environment variable.
Here’s how to do it:
sudo nano /lib/systemd/system/docker.service
Find the line that starts with ExecStart
and modify it to include the -H
flag for the remote API:
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
Save and restart Docker:
sudo systemctl daemon-reload
sudo systemctl restart docker
On your local machine, you can now connect to the remote engine by running:
export DOCKER_HOST=tcp://<your-droplet-ip>:2375
docker ps
For production setups, exposing the Docker API on an open port is risky. Here’s how to secure it:
Option 1: Use SSH Tunnels Create an SSH tunnel to your remote Droplet:
ssh -L 2375:localhost:2375 root@<your-droplet-ip>
Then point your DOCKER_HOST
to localhost
instead:
export DOCKER_HOST=tcp://localhost:2375
docker ps
Option 2: Use Certificates Configure Docker to use TLS certificates for authentication. The official Docker docs have step-by-step instructions for this.
Regarding the benefits, I would say that they are:
And for the downsides:
If you want to dive deeper into Docker, I’ve got a free eBook that might help: Introduction to Docker. It covers the basics of Docker, setting up environments, and much more.
Also, here is a great video that also covers the above!
Hope this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.