Docker + DNSMasq + Traekif como proxy reverso

❗️Pré-requisitos

  • Docker
  • Docker-compose
  • Linux

Introdução

Configurando a infra

mkdir dev-stack && cd dev-stack
listen-address=0.0.0.0
interface=eth0
user=root
no-resolv
server=8.8.8.8
server=8.8.4.4
address=/.test/127.0.0.1
providers:
docker:
defaultRule: "Host(`{{ trimPrefix `/` .Name }}.test`)"
api:
insecure: true
docker network create my-network
version: "3.3"services:  dnsmasq:
image: andyshinn/dnsmasq
cap_add:
- NET_ADMIN
restart: always
ports:
- "53:53/udp"
- "53:53/tcp"
volumes:
- ./dnsmasq.conf:/etc/dnsmasq.conf
command: --log-facility=-
traefik:
image: "traefik:v2.2"
container_name: "traefik"
restart: always
command:
- "--log.level=ERROR"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik.yml:/etc/traefik/traefik.yml"
networks:
default:
external:
name: my-network
docker-compose up -d
Imagem da configuração de DNS no MacOS.

Subindo nossa aplicação

mkdir meu-app && cd meu-app
<?phpecho gethostname();
version: '3'services:
php:
image: fabiojanio/php:8.0-alpine3.14
labels:
- traefik.http.routers.php.rule=Host(`my-app.test`)
volumes:
- ./src/:/app
working_dir: /app
restart: on-failure
user: www-data
command: >
sh -c "php -S 0.0.0.0:80 index.php"
networks:
default:
external:
name: my-network
docker-compose up -d
docker-compose up -d --scale php=3

--

--

--

Palestrante, analista de sistemas e webmaster. Apaixonado pelo universo da tecnologia e um profundo admirador da filosofia do software livre.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fábio Jânio

Fábio Jânio

Palestrante, analista de sistemas e webmaster. Apaixonado pelo universo da tecnologia e um profundo admirador da filosofia do software livre.

More from Medium

How to version Docker images with GitLab CI/CD

Deploying Spectrum Scale with Ansible - Part2 - Multiple Nodes

Run your first “Ansible” playbook

Starting stopped docker container