This guide prepares your mac so you can access your docker containers by their docker-compose project name. So if you have a container with the label com.docker.compose.project=myapp
running you will be able to access it on the url myapp.docker
.
This guide assumes that you are already have a working dnsmasq setup on your mac. The follwing command resolves to 127.0.0.1:
dig @localhost myapp.dev
Create the file in /etc/resolver/docker
with the following content:
nameserver 127.0.0.1
This lets you resolve the tld .docker to 127.0.0.1.
Now add the folloing line to dnsmasq.conf
:
address=/docker/127.0.0.1
Nginx and Docker must be already installed. If not:
brew cask install docker
brew install nginx
Then install docker-gen:
brew install docker-gen
Docker-gen needs a template to automatically create vhost configurations. Copy this template to your machine:
curl https://gist.githubusercontent.com/neckhair/b9fdacec5d2e8b301ade47e37aac1755/raw/b6ca8c9e7b9e26aec104711513b205b321413a68/docker-gen.tmpl -o /usr/local/etc/docker-gen.tmpl
To run the service automatically in the background copy the service plist file to the following location:
curl https://gist.githubusercontent.com/neckhair/b9fdacec5d2e8b301ade47e37aac1755/raw/b0ffacf149a6ec1c7014ece213a10f3bd3637620/ch.nine.docker-gen.plist -o /Library/LaunchDaemons/ch.nine.docker-gen.plist
sudo launchctl load -w /Library/LaunchDaemons/ch.nine.docker-gen.plist
I created an Ansible role to automate the process. You could use this if you want: https://github.com/neckhair/ansible-role-docker-gen/blob/master/tasks/main.yml.
Don't forget to add
address=/docker/127.0.0.1
todnsmasq.conf
if you're not using.dev
!