Devbox by Docker for local development
This guide is for MacOS, but will work on Linux with minor modifications.
- Dnsmasq
- Traefik v2
- MySQL
- PostgreSQL (optional)
- Mailhog
- Clone this repository to your local before we start
git clone https://github.com/lbngoc/DevBox.git && \
cd DevBox
- Setup MacOS to take into account our local docker resolver
sudo mkdir -p /etc/resolver && \
echo "nameserver 127.0.0.1" | sudo tee -a /etc/resolver/test > /dev/null
- Setup a local trusted Root CA and create a TLS certificate for using https in local (shout out to mkcert).
brew install mkcert
brew install nss # only if you use Firefox
mkcert -install
mkcert -cert-file certs/local.crt -key-file certs/local.key localhost "*.localhost" 127.0.0.1 ::1 this.test "*.this.test"
touch traefik/acme.json && chmod 600 acme.json && \
docker network create proxy
Setup dashboard authentication (optional)
- Generate
USER:PASSWORD
for access Traefik dashboard
echo $(htpasswd -nb <USER> <PASSWORD>) | sed -e s/\\$/\\$\\$/g
- Replace USER:PASSWORD in
docker-compose.yml:42
- Uncomment
docker-compose.yml:41
docker-compose.yml:42
Or we can create new file docker-compose.override.yml
version: '3'
services:
traefik:
labels:
- "traefik.http.middlewares.traefik-auth.basicauth.users=USER:PASSWORD"
- "traefik.http.routers.traefik.middlewares=traefik-auth"
Done, we need to start Traefik at first time
docker-compose up -d
Go on https://localhost or https://traefik.this.test you should have the traefik web dashboard serve over https
- When starting any new projects, just use this sample config
version: '3'
services:
wordpress:
image: wordpress
container_name: wordpress
restart: unless-stopped
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: root
WORDPRESS_DB_NAME: wordpress
volumes:
- ./public_html:/var/www/html
labels:
- "traefik.enable=true"
- "traefik.http.routers.wordpress.entrypoints=http"
- "traefik.http.routers.wordpress.rule=Host(`wordpress.this.test`)"
networks:
default:
external:
name: proxy
Then run docker-compose up
then open browser and go to http://wordpress.this.test
I also put a sample config to start whoami container, that will prints OS information and HTTP request to output
docker-compose -f whoami.yml up
Go on https://whoami.this.test to see the result