Compile docker using the patch described at docker/docker#5813 dynbinary and netgo. This disables the netgo
package, which doesn't support mDNS name resolution. You can use my gist michaelmaltese/docker.rb:
brew install https://gist.githubusercontent.com/michaelmaltese/1756c9ce071dea6c4edf/raw/3976a993814d46febf144754f7f3bfe22cebed2f/docker.rb
Install boot2docker-cli, which adds a host-only interface to the boot2docker VM. A pull request for Homebrew is at Homebrew/homebrew#29513 boot2docker-cli: 0.9.2 (new formula), but for now you can do
brew install https://raw.githubusercontent.com/mhubig/homebrew/dffb4f449957e2beac4d226b18640452b93aa37d/Library/Formula/boot2docker-cli.rb
Put this in ~/.profile
:
export DOCKER_HOST=tcp://docker.local:4243
Put this in an executable file somewhere, maybe /usr/local/bin/b2d
:
#!/bin/bash
function control_c()
{
echo
echo "system | received SIGINT at $(date +%H:%M:%S)"
echo "system | stopping boot2docker at $(date +%H:%M:%S)"
boot2docker stop | sed s/^/"boot2d | "/g
echo "system | exited at $(date +%H:%M:%S)"
exit
}
trap control_c SIGINT
echo "system | $(date +%H:%M:%S) started"
echo "system | $(date +%H:%M:%S) starting boot2docker"
boot2docker up 2>&1 | sed s/^/"boot2d | "/g
echo "system | $(date +%H:%M:%S) getting host-only IP address"
DOCKER_IP=$(boot2docker ssh ip addr 2>/dev/null |awk '
/inet/ { ip[$NF] = $2; sub(/\/.*$/,"",ip[$NF]) }
END { print ip["eth1"] }
')
while test -z "${DOCKER_IP}"; do
DOCKER_IP=$(boot2docker ssh ip addr 2>/dev/null |awk '
/inet/ { ip[$NF] = $2; sub(/\/.*$/,"",ip[$NF]) }
END { print ip["eth1"] }
')
done
echo "system | $(date +%H:%M:%S) host-only IP address is ${DOCKER_IP}"
echo "system | $(date +%H:%M:%S) starting mDNS service discovery"
dns-sd -P boot2docker _docker._tcp local 4243 docker.local ${DOCKER_IP} | sed s/^/"dns-sd | "/g
control_c
Now you can start Docker and mDNS service discovery in one window:
$ boot2docker init
...
$ b2d
system | 15:05:32 started
system | 15:05:32 starting boot2docker
boot2d | 2014/05/25 15:05:32 Waiting for SSH server to start...
boot2d | 2014/05/25 15:05:32 Started.
boot2d | 2014/05/25 15:05:32 To connect the Docker client to the Docker daemon, please set:
boot2d | 2014/05/25 15:05:32 export DOCKER_HOST=tcp://localhost:4243
system | 15:05:32 getting host-only IP address
system | 15:05:34 host-only IP address is 192.168.59.103
system | 15:05:34 starting mDNS service discovery
dns-sd | Registering Service boot2docker._docker._tcp.local host docker.local port 4243
dns-sd | DATE: ---Sun 25 May 2014---
dns-sd | 15:05:34.240 ...STARTING...
dns-sd | 15:05:35.130 Got a reply for record docker.local: Name now registered and active
dns-sd | 15:05:35.130 Got a reply for service boot2docker._docker._tcp.local.: Name now registered and active
and do things like:
$ docker run -d -p 27017:27017 --name mongodb dockerfile/mongodb
$ mongo docker.local
MongoDB shell version: 2.6.1
connecting to: docker.local/test
>