DEV Community

Harish Agrawal
Harish Agrawal

Posted on

Docker running inside a VM, how do I access?

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

/etc/systemd/system/docker.service.d/override.conf

sudo systemctl edit docker
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:50000 -H unix:///var/run/docker.sock

Reload the changed configuration

sudo systemctl daemon-reload

Verify the changed configuration

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

Restart Docker Daemon Service (using systemctl or service)

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

Check the docker daemon logs or process to verify TCP binding

sudo systemctl status docker
OR
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://0.0.0.0:5000 -H unix:///var/run/docker.sock >> /tmp/dockerd.log 2>&1 &

Top comments (0)