This project provides a basic Docker setup, for building a local development environment with HTTPS support.
Devindocker run a container with a reverse proxy and load balancer called Træfik. This will be the only container to expose a port to our docker host. The containers of the different projects and the træfik container will be in the same docker network. Træfik will forward the requests from the client to the corresponding container.
- docker
- docker-compose
- mkcert for SSL certificate
- no other services listening port 80 and 443
- Træfik HTTP reverse proxy and load balancer made to deploy microservices with ease.
- Portainer Simple management UI for Docker.
- MailHog Web and API based SMTP testing.
# If it's the firt install of mkcert, run
mkcert -install
# Generate certificate for domain "d.test" and their sub-domains
mkcert -cert-file certs/d.test-cert.pem -key-file certs/d.test-key.pem "d.test" "*.d.test"
Copy the default .env
file als startpoint:
cp .env_default .env
Change something if you want to.
Using Dnsmasq as a local resolver.
Install Dnsmasq with brew
brew install dnsmasq
Create the etc dir if needed
mkdir -p /usr/local/etc
Create a simple configuration, where all .test domains would respond with 127.0.0.1
echo "address=/.test/127.0.0.1" > /usr/local/etc/dnsmasq.conf
Install the daemon startup file
sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
Start the daemon
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
All we need to do is tell the resolver to use Dnsmasq for .test domains:
# man 5 resolver
sudo mkdir -p /etc/resolver
sudo sh -c 'echo "nameserver 127.0.0.1" > /etc/resolver/test'
Now you can use any .test domain and it will always resolve to 127.0.0.1
.
You can easily create new domains on the fly, and never have to worry about your /etc/hosts
file again.
Source: Setting up a wildcard DNS domain on Mac OS X - ASCII Thoughts
Start the containers normally:
docker-compose up -d
- Træfik (https://traefik.d.test)
- Portainer (https://portainer.d.test)
- MailHog (https://mailhog.d.test)
To create another project you need to add træfik labels inside the container that need to be access from the outside and add dev-in-docker network.
labels:
- "traefik.enable=true"
- "traefik.http.routers.${CONTAINER_NAME}.entrypoints=https"
- "traefik.http.routers.${CONTAINER_NAME}.rule=Host(`${APP_URL}`)"
- "traefik.http.routers.${CONTAINER_NAME}.tls=true"
- "traefik.docker.network=dev-in-docker-network"
- "traefik.http.services.${CONTAINER_NAME}.loadbalancer.server.port=80"
networks:
default:
internal: true
# Network from dev-in-docker
dev-in-docker-network:
name: "dev-in-docker-network"
external: true