I would like to have custom sub domains that forward to different container / port combo’s in my docker instance similar to how POW and “*.dev” domains works in the Mac world.
Only the HOST docker resolves to the VM’s IP address.
Projects like http://mayakron.altervista.org/wikibase/show.php?id=AcrylicHome allow for wild card domains but seem to interfere with the docker dns proxy and breaks container networking when my local networking devices are pointed to localhost for DNS resolution.
Existing projects like https://github.com/jwilder/nginx-proxy proxy require sharing the docker socket with the image which I’m not sure is possible in Windows. Also Skydock looks interesting but requires docker to be started with a custom DNS server which I’m not sure is possible. Another potential project that could be relevant is Prax
Seems like the problem can be broken into two parts:
- Resolve wildcard subdomains to the docker VM
- Proxy requests to different containers based on HOST
I have used a combination of docker-dns and dnsmasq to use dns my my local machine. First I would stop the docker service, and change the docker opts:
DOCKER_OPTS="--bip=192.168.20.10/24 --dns 192.168.20.1 --dns-search example.com"
in dnsmasq (you will need linux for this):
Or you can add 192.168.20.1 as a nameserver in your network settings, but this caused issued resolving the real internet.
Then I would start docker, and spin up docker-dns as my first container so it gets the 192.168.20.1 address:
docker run --name dns -v /var/run/docker.sock:/docker.sock phensley/docker-dns \
now any container you run will have a dns entry.
However. Recently I have been playing with rancher, and I wanted to create my own dns service, because docker-dns needs to attached itself to the daemon, which I don’t like, and I wanted to use pointHQ which integrated with rancher. After going through the headache of trying to run my own dns private service, I decided to just get a real domain. Since this was for development I did not need a fancy tld, so I headed over to namecheap.com, and for the price of a fancy coffee you have a domain like yourdomain.xyz for a year.
It’s a bit trickier with a Windows setup. I can’t figure out how to bind to the docker socket and I’m not sure we can actually change the DNS options for the docker daemon. I know the windows client ships with a custom DNS server. Is there any plan to allow adding entries to it down the road?
Im guessing your using kitematic as your frontend to your docker. which means virtualbox is your back end. Which means you need to get into the boot2docker image and modify the docker settings that way. you can get to the shell with the quickstart terminal provided with the kitematic toolbox. Or you can ssh into boot2docker with docker-machine from the CMD prompt. The docker configuration should be /etc/default/docker, edit this with vi or nano. here you can also run the docker command like docker ps.
the config file docker on boot2docker is /var/lib/boot2docker/profile
EXTRA_ARGS="–bip=192.168.20.10/24 --dns 192.168.20.1 --dns-search example.com"
I’m actually using the new docker for windows beta which uses Hyper-V instead of VirtualBox. It’s not clear to me how it’s doing all of it’s voodoo magic as
docker-machine doesn’t seem to list any machines, but I can run
docker commands just fine.
Open the command prompt (type cmd in to the search). If everything has been installed correctly, the command docker-machine should work. type
docker-machine ls, should show your machines.
docker-machine active shows your active machine, and
docker-machine ssh should get you a terminal into the machine.
docker-machine env machinename should show you the commands you need to run so your environment is setup to use the machine
C:\Users\chris>docker-machine env default
REM Run this command to configure your shell:
REM FOR /f "tokens=*" %i IN ('docker-machine env default') DO %i
so you would run
FOR /f "tokens=*" %i IN ('docker-machine env default') DO %i to setup your environment,. It sounds like your environment is already setup so you may not need to do this. but it is interesting to know. You can also provsion new machines with the docker-machine create --driver hyperv machinename command.
what happens when you run
docker-machine ssh in your command prompt?
The new docker for windows beta isn’t hooked up to docker-machine I guess. My docker command works fine, but I’m unable to see the machine that is obviously running:
PS C:\GitHub\projects\flower_ai> docker-machine active
No active host found
PS C:\GitHub\projects\flower_ai> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5337efbb8cc postgres:9.4 "/docker-entrypoint.s" 21 hours ago Up About a minute 5432/tcp flowerai_herokuPostgresql_1
and how about the output
docker-machine ls?, If that has a result, try running the env commands and setup your environment anyways .
@vanpelt @paxmanchris you cannot use
docker-machine to manage your Docker for Mac/Windows installation, but
docker-machine included in case you want to create remote Dockerized machines.
You can share the docker socket:
docker run -it -v /var/run/docker.sock:/var/run/docker.sock nathanleclaire/devbox
~$ DOCKER_HOST=unix:///var/run/docker.sock docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9ed11c04d1d0 nathanleclaire/devbox /bin/bash 21 seconds ago Up 20 seconds suspicious_ritchie
@vanpelt can you expand on your use cases for wanting to access Docker containers over the network from the host?
Thanks @friism I’m hoping to achieve something similar to http://pow.cx. Specifically I have some web apps that check for certain sub-domains to configure routes. Simply being able to point “api.docker” to the docker machine ip would be a good start (I could do this manually by modifiyng /etc/hosts but it’s not ideal). I think there’s a ton of value in being able to proxy requests to pre-defined ports on the docker machine. Especially for web services, needing to remember what service is on what port is a development burden.
Assume you want to run your own DNS, I can recommend using PowerDNS.
You can find a docker container in DockerHub, it has UI, it support all DNS type records, it has simple configuration and it also support REST API therefore no downtime. I used it before we moved to Kubernetes that support DNS using SkyDNS
@vanpelt any luck getting it configured, looking for similar configuration and unclear if I should run DNS server on the host or in a container within Docker VM
Hey @ketpat8 I wasn’t able to come up with a solution. I still think there’s promise in the proxy that ships with Docker for Windows. At the very least it could proxy
*.docker to the docker IP and then you could run nginx or another proxy on port 80 to route to the different apps.
I’m +1 on this feature, but for Docker for Mac too.
I’ve been using Dinghy https://github.com/codekitchen/dinghy and they have this functionality, it helps a lot in development.
One +1 on this feature
Found few more tools that works locally:
But i would like to have only Docker Toolbox installed and
*.docker resolved to host IP.