Docker running inside a VM, how do I access?

harishagrawal profile image Harish Agrawal ・2 min read

Have you ever struggled to get Docker running on your local host?
Only to realize that once you have it all figured out, the actual scenario requires you to repeat the exercise but now inside a virtual machine (possibly running a Linux flavor).

Or what if docker daemon was best running at only one place instead of two?

I want to share a small learning around the docker daemon start options and how to leverage it for our benefit.

How to "run inside a Linux VM"?

Start docker daemon to listen on multiple sockets (TCP as well as Unix)

Edit the Docker service configuration


sudo systemctl edit docker
ExecStart=/usr/bin/docker daemon -H tcp:// -H unix:///var/run/docker.sock

Reload the changed configuration

sudo systemctl daemon-reload

Verify the changed configuration

sudo systemctl cat docker | grep ExecStart
sudo systemctl show --property=ExecStart docker

Restart Docker Daemon Service (using systemctl or service)

sudo systemctl restart docker
sudo service docker stop
sudo service docker start

Check the docker daemon logs or process to verify TCP binding

sudo systemctl status docker
ps faux | grep docker

Finally, access docker on the host using DOCKER_HOST

Assume your VM host alias name is "myVMHostAlias"

export DOCKER_HOST=myVMHostAlias:50000
docker images

Tried the above, but its not working

If the above fails to achieve the end-objective, then you can always stop the dockerd service and start one manually
sudo service docker stop
sudo /usr/bin/dockerd -H tcp:// -H unix:///var/run/docker.sock >> /tmp/dockerd.log 2>&1 &

Posted on by:

harishagrawal profile

Harish Agrawal


Product Engineer at core, I yearn to learn always


markdown guide