Published on:
2023-10-07
#traefik #docker #docker-swarm #load-balancing #fault-tolerance #cloud-native #reverse-proxy #https-termination #high-availability
Table of Contents

version: '3.8'
services:
db:
image: postgres
environment:
POSTGRES_USER: manager
POSTGRES_PASSWORD: password123
POSTGRES_DB: postgres
volumes:
- "./postgresql/data:/var/lib/postgresql/data"
networks:
- net1
healthcheck:
test: ["CMD-SHELL", "pg_isready -U manager"]
interval: 5s
timeout: 5s
retries: 5
odoo:
image: odoo:latest
depends_on:
- db
environment:
POSTGRES_USER: manager
POSTGRES_PASSWORD: password123
POSTGRES_DB: postgres
volumes:
- ./odoo/data_dir:/var/lib/odoo
- ./odoo/conf:/etc/odoo
deploy:
mode: replicated
replicas: 3
networks:
- net1
labels:
- "traefik.enable=true"
- "traefik.http.routers.odoo.rule=Host(`odoo.m0d4s.me`)"
- "traefik.http.services.odoo.loadbalancer.server.port=8069"
traefik:
image: traefik:latest
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--entrypoints.websecure.http.tls=true"
- "--certificatesResolvers.myresolver.acme.tlsChallenge=true"
ports:
- "80:80"
- "8080:8080"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./certs:/odoo-certs
networks:
- net1
labels:
- "traefik.http.routers.traefik.rule=Host(`traefik.m0d4s.me`)"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.routers.odoo-https.rule=Host(`odoo-sec.m0d4s.me`)"
- "traefik.http.routers.odoo-https.entrypoints=websecure"
- "traefik.http.routers.odoo-https.tls=true"
- "traefik.http.routers.odoo-https.tls.certificates[0]=/odoo-certs/odoo.crt"
- "traefik.http.routers.odoo-https.tls.certificates[1]=/odoo-certs/odoo.key"
networks:
net1:The db service is a simple postgresql database that will be used by odoo. It is configured to use a volume to store its data and a network to communicate with the other services. It also has a healthcheck that will check if the database is up and running. If it is not, the service will be restarted. This is useful when we want to deploy the services in a swarm. The swarm will automatically restart the service if it is down.
docker swarm init
docker stack deploy -c docker-compose.yml traefik_lb
# If you need to change the number of replicas of the odoo service, you can run the following command:
docker service scale traefik_lb_odoo=5docker service lssudo echo '127.0.0.1 traefik.m0d4s.me odoo.m0d4s.me odoo-sec.m0d4s.me' >> /etc/hostscurl -k https://127.0.0.1 -H "Host: odoo-sec.m0d4s.me"docker stack rm traefik_lbdocker swarm leave --force