version: "3.6"
networks:
frontend:
name: frontend
driver: bridge
backend:
name: backend
driver: bridge
traefik:
name: traefik
driver: bridge
external: true
services:
# -------------------
# NGINX
# -------------------
nginx:
container_name: nginx
build:
context: ./
dockerfile: ./frontend/Dockerfile
networks:
- frontend
- backend
- traefik
labels:
# ---------------------- expose application through Traefik
- "traefik.enable=true"
- "traefik.http.routers.nginx.rule=Host(`${CLIENT_DOMAIN_NAME}`)"
# -------------------
# TRAEFIK
# -------------------
traefik:
image: traefik:latest
ports:
- "80:80"
- "443:443"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro # for starting / stopping containers, and inspecting their labels for Traefik instructions
- ./traefik/traefik.yml:/etc/traefik/traefik.yml
- ./traefik/dynamic.yml:/etc/traefik/dynamic.yml
networks:
- traefik
labels:
# ---------------------- CORS
- "traefik.http.middlewares.corsMiddleware3.headers.accesscontrolalloworiginlist=*"
- "traefik.http.middlewares.corsMiddleware3.headers.customResponseHeaders.Access-Control-Allow-Origin=*"
- "traefik.http.routers.traefik.middlewares=corsMiddleware3"
# -------------------
# NODEJS
# -------------------
node:
image: node:18
build:
context: ./backend
volumes:
- ./backend:/app:cached
depends_on:
- nginx
- traefik
networks:
- frontend
- backend
- traefik
labels:
# ---------------------- expose application through Traefik
- "traefik.enable=true"
- "traefik.http.routers.node.rule=Host(`backend-${CLIENT_DOMAIN_NAME}`)"
# ---------------------- CORS
- "traefik.http.middlewares.corsMiddleware.headers.accesscontrolallowheaders=X-Requested-With, Content-Type, Content-Length, Authorization"
- "traefik.http.middlewares.corsMiddleware.headers.accesscontrolalloworiginlist=*"
- "traefik.http.middlewares.corsMiddleware.headers.accesscontrolallowmethods=GET, POST, OPTIONS"
- "traefik.http.middlewares.corsMiddleware.headers.accesscontrolmaxage=120"
- "traefik.http.middlewares.corsMiddleware.headers.addvaryheader=true"
- "traefik.http.routers.node.middlewares=corsMiddleware"