Skip to content

Multi-project local development environment & toolset on Docker

Notifications You must be signed in to change notification settings

elalemanyo/dev-in-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dev in docker

This project provides a basic Docker setup, for building a local development environment with HTTPS support.

What does it do?

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.

dev in docker

Requirements

  • docker
  • docker-compose
  • mkcert for SSL certificate
  • no other services listening port 80 and 443

Features

  • 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.

Installation

Generate certificates using mkcert

# 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"

Create .env file

Copy the default .env file als startpoint:

cp .env_default .env

And change something if you need to.

Create træfik config files

Copy the default ones als startpoint:

cp traefik/config_default.yml traefik/config.yml
cp traefik/traefik_default.yml traefik/traefik.yml

And change something if you need to.

Hosts File - Wildcard DNS domain on Mac OS X (optional)

Using Dnsmasq as a local resolver.

Install Dnsmasq with brew

brew install dnsmasq

Create config directory

mkdir -pv $(brew --prefix)/etc/

Setup *.test

echo 'address=/.test/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf

Autostart - now and after reboot

sudo brew services start dnsmasq

Add to resolvers. Create resolver directory

sudo mkdir -v /etc/resolver

Add your nameserver to resolvers

sudo bash -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

Run

Start the containers normally:

docker-compose up -d

Accessing services

Setting a new Project

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

Check some more examples

Setting non docker Project

For all the projects running locally out of docker you can add a route inside traefik/config.yml:

http:
  routers:
    non_docker_service:
      rule: "Host(`non_docker_service.d.test`)"
      service: "non_docker_service"
      tls: {}

  services:
    non_docker_service:
      loadBalancer:
        servers:
          - url: http://host.docker.internal:3000

Now you can call your local running project like this: non_docker_service.d.test

References

Releases

No releases published

Packages

No packages published