- Notifications
You must be signed in to change notification settings - Fork11
🐳 Docker-powered local development environment for macOS and Linux, featuring Traefik with SSL support via mkcert. Streamlines development by eliminating `/etc/hosts` edits, resolving port conflicts. Local domains supported via dnsmasq. Ideal for HTTP-based projects like Laravel or Symfony. Enhances workflow consistency and team productivity.
License
wayofdev/docker-shared-services
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This repository provides a Docker-powered local development environment for Dockerized projects, compatible with macOS and Linux.
It includes a set of docker-compose files andTræfik configuration with SSL support, backed bymkcert, to enable running a local network with custom DNS provided bydnsmasq. This setup facilitates developing microservices locally with access outside the Docker network.
- Key Features
- Purpose
- Benefits for Team
- Requirements
- Quick Start Guide (macOS)
- Quick Start Guide (Linux)
- Connecting your Projects to Shared Services
- Example: Spin-up Laravel Sail Project
- Example: Want to See a Ready-Made Template?
- Security Policy
- Want to Contribute?
- Contributors
- Social Links
- License
- Automated Local DNS and SSL Setup: Eliminates manual edits to
/etc/hostsand self-signed certificate warnings. - Consistent Development Environment: Uniform setup for all team members, reducing environment-related bugs.
- Elimination of Port Conflicts: Traefik handles port management, allowing multiple dockerized projects to run concurrently.
- User-Friendly Local URLs: Access projects via custom local domains like
project.dockerinstead oflocalhost:8000. - Simplified CORS and Cookie Management: SSL support for local domains mirrors production settings.
- Enhanced Testing Environment: Test OAuth, secure cookies, and HTTPS APIs locally.
- Improved Service Discovery and Routing: Traefik automates service discovery and routing within your Docker network.
- Ease of Integration with Existing Projects: Connect your existing Docker projects to this setup effortlessly.
This project simplifies local development by addressing common issues such as:
- Frequent updates to the
/etc/hostsfile. - Requirement of administrative access for changes.
- Lack of SSL support for custom domains.
- Port conflicts when forwarding Docker service ports to the host machine.
- Use of cumbersome hostnames like
localhost:8800for local projects. - Complex CORS setup and Cookie configuration.
For Linux and macOS users, dnsmasq eliminates the need to edit the hosts file for each project, providing a streamlined solution when used with Traefik, mkcert, and Docker. This repository configures Traefik to work with dnsmasq, offering a system-wide DNS solution for microservices and enabling DNS and SSL features with local domains.
Integrating this Docker Shared Services project into your team's tech stack can significantly enhance your development workflow. This setup is compatible with a wide range of HTTP-based projects, including backend frameworks like Laravel, Symfony, or Spiral, frontend frameworks, and any other services that run in Docker and communicate over HTTP.
By standardizing the local network setup across different machines, your team can:
- Maintain consistency.
- Reduce configuration work.
- Resolve port conflicts between multiple Docker services.
- Provide SSL support for local domains.
- Work with CORS and Cookies in a scenario close to production.
- Set up OAuth providers to work with custom local domains.
This ensures smoother collaboration and boosts overall productivity.
If youlike/use this project, please consider ⭐️starring it. Thanks!
- macOS Monterey+ orLinux
- Docker 26.0 or newer
- Installedmkcert binary in system
- See full installation instructions in their officialREADME.md
- Quick installation on macOS:
brew install mkcert nss
Installed and configureddnsmasq daemonCan be installed and configured automatically via ouransible-role-dnsmasq ansible role- DNSMasq service now is shipped and configured with this repository.
Install Homebrew (if not installed):
IfHomebrew is not already installed, run the following command:
/bin/bash -c"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Install Docker (if not installed):
Set up Docker Desktop via Homebrew:
brew install --cask docker
Install
mkcertandnss:mkcertis a tool that creates locally-trusted development certificates, andnssprovides support for mkcert certificates in Firefox.brew install mkcert nss
Create shared project directory:
This repository should be run once per machine, so let's create a shared directory for this project:
mkdir -p~/projects/infra&&cd~/projects/infra
Clone this repository:
git clone \ git@github.com:wayofdev/docker-shared-services.git \~/projects/infra/docker-shared-services&& \cd~/projects/infra/docker-shared-services
Create
.envfile:Generate a default
.envfile, which contains configuration settings for the project.make env
Open this file and read the notes inside to make any necessary changes to fit your setup.
Install root certificate and generate default project certs:
This step installs the root certificate into your system's trust store and generates default SSL certificates for your local domains, which are listed in the
.envfile, under the variableTLS_DOMAINS.make cert-install
[!WARNING]
Currently, on macOS, you may need to enter your password several times to allow
mkcertto install the root certificate.This is a one-time operation and details can be found in this upstream GitHubissue.Run this project:
Start the Docker services defined in the repository.
make up
Check that all Docker services are running:
Ensure Docker is running and services are up by using the
make psandmake logscommands.make psmake logs
Add custom DNS resolver to your system:
This allows macOS to understand that
*.dockerdomains should be resolved by a custom resolver via127.0.0.1, where our DNSMasq, which runs inside Docker, will handle all DNS requests.sudo sh -c'echo "nameserver 127.0.0.1" > /etc/resolver/docker'sudo dscacheutil -flushcachesudo killall -HUP mDNSResponderYou can check that DNS was added by running:
scutil --dns
Example output:
resolver#8domain: dockernameserver[0]: 127.0.0.1flags: Request A records, Request AAAA recordsreach: 0x00030002 (Reachable,Local Address,Directly Reachable Address)
[!NOTE]
Instead of creating the
/etc/resolver/dockerfile, you can add127.0.0.1to your macOS DNS Servers in your Ethernet or Wi-Fi settings.Go toSystem Preferences → Network → Wi-Fi → Details → DNS and add
127.0.0.1as the first DNS server.This allows you to do it one time, and if you need to create a new local domain, for example
*.mac, in the future, it will be automatically resolved without creating a separate/etc/resolver/macfile.Ping
router.dockerto check if DNS is working:Ensure that the DNS setup is functioning correctly.
ping router.docker -c 3ping any-domain.docker -c 3
Access Traefik dashboard:
You should see the Traefik Dashboard:
At this point, you should have a working local development environment with DNS and SSL support ready to be used with your projects.
Services will be running under a shared Docker network callednetwork.ss, and all projects or microservices that will share the sameDocker network will be visible to Traefik. The local DNS, served by DNSMasq, will be available on*.docker domains.
In this section, we'll walk through setting up thedocker-shared-services project on an Ubuntu distribution. While the steps are specific to Ubuntu, they should be adaptable to other Linux distributions with minor modifications.
Install Docker:Easiest and quickest way to get started is toinstall Docker Desktop for Linux.
Install
certutil:sudo apt updatesudo apt install libnss3-tools
Install
mkcert:curl -JLO"https://dl.filippo.io/mkcert/latest?for=linux/amd64"chmod +x mkcert-v*-linux-amd64sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert
More detailed instructions can be found in the
mkcert README.md.Create shared project directory:
mkdir -p~/projects/infra&&cd~/projects/infra
Clone this repository:
git clone \ git@github.com:wayofdev/docker-shared-services.git \~/projects/infra/docker-shared-services&& \cd~/projects/infra/docker-shared-services
Create
.envfile:Generate a default
.envfile, which contains configuration settings for the project.make env
Open this file and read the notes inside to make any necessary changes to fit your setup.
Install root certificate and generate default project certs:
make cert-install
Disable stub DNS listener:
To prevent conflicts with the DNSMasq service, disable the stub DNS listener in the
systemd-resolvedservice.sudo sed -i's/#DNSStubListener=yes/DNSStubListener=no/' /etc/systemd/resolved.confsudo systemctl restart systemd-resolvedEdit /etc/resolv.conf:
Update the
/etc/resolv.conffile to use the local DNS server.echo"nameserver 127.0.0.1"| sudo tee /etc/resolv.conf> /dev/null
Editing
/etc/resolv.confdirectly is not recommended for persistent changes since it is often managed by other services (like Netplan or NetworkManager). However, for a temporary change, you can use:Run this project:
Start the Docker services defined in the repository.
make up
Check that all Docker services are running:
Ensure Docker is running and services are up by using the
make psandmake logscommands.make psmake logs
Ping
router.dockerto check if DNS is working:Ensure that the DNS setup is functioning correctly.
ping router.docker -c 3ping any-domain.docker -c 3
Access Traefik dashboard:
You should see the Traefik Dashboard:
At this point, you should have a working local development environment with DNS and SSL support ready to be used with your projects.
Services will be running under a shared Docker network callednetwork.ss, and all projects or microservices that will share the sameDocker network will be visible to Traefik. The local DNS, served by DNSMasq, will be available on*.docker domains.
To connect your projects to the shared services, configure your project'sdocker-compose.yaml file to connect to the shared network and Traefik.
This project comes with an example Portainer service, which also starts by default with themake up command. You can check thedocker-compose.yaml to see how Traefik labels and the shared network are used to spin up Portainer on thehttps://ui.docker host, which supports SSL by default.
Your project should use the shared Docker networknetwork.ss and Traefik labels to expose services to the outside world.
Change your project's
docker-compose.yamlfile:---services: web: image: wayofdev/nginx:k8s-alpine-latest restart: on-failure+ networks:+ - default+ - shared volumes: - ./app:/app:rw,cached+ labels:+ - traefik.enable=true+ - traefik.http.routers.api-my-project-secure.rule=Host(`api.my-project.docker`)+ - traefik.http.routers.api-my-project-secure.entrypoints=websecure+ - traefik.http.routers.api-my-project-secure.tls=true+ - traefik.http.services.api-my-project-secure.loadbalancer.server.port=8880+ - traefik.docker.network=network.ssnetworks:+ shared:+ external: true+ name: network.ss+ default:+ name: project.my-project
In this configuration, we added the shared network and Traefik labels to the web service. These labels help Traefik route the traffic to the service based on the specified rules.
Replace
my-projectwith your preferred project name.Generate SSL certs for your project:
Go to the
docker-shared-servicesdirectory:cd~/projects/infra/docker-shared-services
Edit the
.envfile to add your custom domain:nano .env
Add
*.my-project.dockerto end ofTLS_DOMAINSvariable:TLS_DOMAINS="ui.docker router.docker *.my-project.docker"Generate SSL certificates and reload
docker-shared-services:make cert-install restart
Let's walk through an example of setting up a Laravel project using Sail and integrating it with thedocker-shared-services.
Create an example Laravel project based on Sail:
curl -s"https://laravel.build/example-app"| bash
Open the
docker-compose.yamlfile of theexample-appproject and make adjustments:services: laravel.test: build: context: ./vendor/laravel/sail/runtimes/8.3 dockerfile: Dockerfile args: WWWGROUP: '${WWWGROUP}' image: sail-8.3/app- extra_hosts:- - 'host.docker.internal:host-gateway' ports:- - '${APP_PORT:-80}:80'- - '${VITE_PORT:-5173}:${VITE_PORT:-5173}' networks: - sail+ - shared depends_on: - ...+ labels:+ - traefik.enable=true+ - traefik.http.routers.test-laravel-app-secure.rule=Host(`api.laravel-app.docker`)+ - traefik.http.routers.test-laravel-app-secure.entrypoints=websecure+ - traefik.http.routers.test-laravel-app-secure.tls=true+ - traefik.http.services.test-laravel-app-secure.loadbalancer.server.port=80+ - traefik.docker.network=network.ss mailpit: image: 'axllent/mailpit:latest' networks: - sail+ - shared ports:- - '${FORWARD_MAILPIT_PORT:-1025}:1025'- - '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'+ labels:+ - traefik.enable=true+ - traefik.http.routers.mail-laravel-app-secure.rule=Host(`mail.laravel-app.docker`)+ - traefik.http.routers.mail-laravel-app-secure.entrypoints=websecure+ - traefik.http.routers.mail-laravel-app-secure.tls=true+ - traefik.http.services.mail-laravel-app-secure.loadbalancer.server.port=8025+ - traefik.docker.network=network.ssnetworks: sail: driver: bridge+ shared:+ external: true+ name: network.ssThese changes connect the Laravel app and Mailpit docker services to the shared network and expose them via Traefik.
Run the Laravel project:
Navigate to the
example-appdirectory and start the services using Sail../vendor/bin/sail up -d
Check Traefik routers:
Openhttps://router.docker/dashboard/#/http/routers and check that there are two routers:
Host(api.laravel-app.docker)→test-laravel-app-secure@dockerHost(mail.laravel-app.docker)→mail-laravel-app-secure@docker
Check the setup:
Ensure that your Laravel application and Mailpit services are running correctly by accessing their respective domains:
- Laravel app —https://api.laravel-app.docker
- Mailpit —https://mail.laravel-app.docker
At this point, your Laravel project is integrated with thewayofdev/docker-shared-services, utilizing DNS and SSL support for local development.
If you come from the PHP or Laravel world, or if you want to see how a complete project can be integrated withdocker-shared-services, check outwayofdev/laravel-starter-tpl.
This Dockerized Laravel starter template works seamlessly withwayofdev/docker-shared-services, providing a foundation with integrated DNS and SSL support, and can show youthe way to implement patterns, stated in this article, in your projects.
This project has asecurity policy.
Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:
- 🤔Suggest a feature
- 🐛Report an issue
- 📖Improve documentation
- 👨💻 Contribute to the code
You are more than welcome. Before contributing, kindly check ourcontribution guidelines.
- Twitter: Follow our organization@wayofdev and the author@wlotyp.
- Discord: Join our community onDiscord.
About
🐳 Docker-powered local development environment for macOS and Linux, featuring Traefik with SSL support via mkcert. Streamlines development by eliminating `/etc/hosts` edits, resolving port conflicts. Local domains supported via dnsmasq. Ideal for HTTP-based projects like Laravel or Symfony. Enhances workflow consistency and team productivity.
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.


