Make docker machine available under host name in Windows

Viewed 7182

I'm trying to make a docker machine available to my Windows by a host name. After creating it like

docker-machine create -d virtualbox mymachine

and setting up a docker container that exposes the port 80, how can I give that docker machine a host name such that I can enter "http://mymachine/" into my browser to load the website? When I change "mymachine" to the actual IP address then it works.

There is an answer to this question but I would like to achieve it without an entry in the hosts file. Is that possible?

6 Answers

If you're on a machine with Multicasting DNS (that's Bonjour on a Mac), then the approach that's worked for me is to fire up an Avahi container in the Docker Machine vbox. This lets me refer to VM services at <docker-machine-vm-name>.local. No editing /etc/hosts, no crazy networking settings.

I use different Virtualbox VMs for different projects for my work, which keeps a nice separation of concerns (prevents port collisions, lets me blow away all the containers and images without affecting my other projects, etc.)

Using docker-compose, I just put an Avahi instance at the top of each project:

version: '2'
services:
    avahi:
        image: 'enernoclabs/avahi:latest'
        network_mode: 'host'

Then if I run a webserver in the VM with a docker container forwarding to port 80, it's just http://machine-name.local in the browser.

Related