-1

I’m having a problem and I can’t find a solution.

I have deployed a Django backend and a React frontend using Docker.

I’m using Traefik as a reverse proxy for the web server. When I start Traefik, the backend, and the frontend, everything works perfectly.

However, when I try to upgrade my apps, the backend becomes unreachable (504). To fix it, I have to restart Traefik and then start the backend after Traefik. After that, it works again.

This is my backend Docker Compose:

services:
  backend:
    image: backend-v3:latest
    container_name: dashboard-backend
    restart: always
    env_file:
      - ./dashboard/.dockerenv
    volumes:
      - .:/app
      - ./infra/static:/app/staticfiles
    networks:
      - traefik
      - db_network
    ports:
      - "8000:8000"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.django-api.rule=Host(`domain.com`)"
      - "traefik.http.routers.django-api.entrypoints=websecure"
      - "traefik.http.routers.django-api.tls=true"
      - "traefik.http.routers.django-api.tls.certresolver=myresolver"
      - "traefik.http.services.django-api.loadbalancer.server.port=8000"

    healthcheck:
      test: ["CMD-SHELL", "python3 -m urllib.request http://localhost:8000/health/ || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 5

networks:
  traefik:
    external: true
  db_network:
    external: true

And this is how I start Traefik:

#!/bin/bash
docker run -d \
  --name traefik \
  --network traefik \
  --restart=always \
  -p 80:80 \
  -p 443:443 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /opt/traefik/acme.json:/acme.json \
  -l "traefik.enable=true" \
  -l "traefik.http.routers.traefik.rule=Host(\"traefik.domain.com\")" \
  -l "traefik.http.routers.traefik.entrypoints=websecure" \
  -l "traefik.http.routers.traefik.tls.certresolver=myresolver" \
  -l "traefik.http.routers.traefik.middlewares=auth,redirect" \
  -l "traefik.http.middlewares.auth.basicauth.users=admin:$apr1$T1Xpq5XX$4AogYQokV4FbJLKOKwCBl0" \
  -l "traefik.http.middlewares.redirect.redirectscheme.scheme=https" \
  -l "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https" \
  -l "traefik.http.services.traefik.loadbalancer.server.port=8080" \
  traefik:v3.1 \
    --api.insecure=false \
    --providers.docker=true \
    --entrypoints.web.address=:80 \
    --entrypoints.websecure.address=:443 \
    --certificatesresolvers.myresolver.acme.httpchallenge=true \
    --certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web \
    --certificatesresolvers.myresolver.acme.email=email.com \
    --certificatesresolvers.myresolver.acme.storage=/acme.json \
    --providers.docker.watch=true \
    --providers.docker.exposedbydefault=false

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.