Traefik with two sites, the second one up does not work half the time

Hi !

I'm behaving very strangely with Traefik... I feel like he's getting mixed up. I have a Traefik which allows me to manage my two websites locally, to launch them in parallel. Here are my compositions:

On Project/infrastructure/docker-compose.yml

version: '3'

services:
  reverse-proxy:
    image: traefik:v3.0
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entryPoints.web.address=:80"
      - "--log.level=DEBUG"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.traefik-secure.entrypoints=web"
      - "traefik.http.routers.traefik-secure.rule=Host(`monitoring.localhost`)"
      - "traefik.http.routers.traefik-secure.service=api@internal"
    networks:
      - traefik

networks:
  traefik:
    external: true

And my two sites look like this:

Project/site1/docker-compose.yml - COMPOSE_PROJECT_NAME=site1

Project/site2/docker-compose.yml - COMPOSE_PROJECT_NAME=site2

version: '3'

services:
  php:
    container_name: "${COMPOSE_PROJECT_NAME}-php"
    build:
      context: ./config/php/${PHP_VERSION}-fpm
      args:
        COMPOSER_VERSION: ${COMPOSER_VERSION}
        ENABLE_XDEBUG: ${ENABLE_XDEBUG}
        ENABLE_WKHTMLTOPDF: ${ENABLE_WKHTMLTOPDF}
        ENABLE_BLACKFIRE: ${ENABLE_BLACKFIRE}
    volumes:
      - ${APP_FOLDER}:/var/www
    networks:
      - traefik
  nginx:
    container_name: "${COMPOSE_PROJECT_NAME}-nginx"
    build:
      context: ./config/nginx
    volumes:
      - ${APP_FOLDER}:/var/www
      - ./config/nginx/nginx-${PROJECT_TYPE}.conf:/etc/templates/nginx.conf
      - ./logs:/var/log/nginx
      - ./nginx/certs:/etc/nginx/certs
    environment:
      ADMIN_FOLDER_PRESTASHOP: ${ADMIN_FOLDER_PRESTASHOP}
    depends_on:
      - php
    labels:
      # Traefik 2.0
      - "traefik.enable=true"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}.entrypoints=web"
      - "traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host(`${COMPOSE_PROJECT_NAME}.localhost`)"
      - "traefik.docker.network=traefik"
    networks:
      - traefik
  nodejs:
    container_name: "${COMPOSE_PROJECT_NAME}-nodejs"
    image: "nikolaik/python-nodejs:latest"
    working_dir: /var/www/
    environment:
      - NODE_ENV=development
    volumes:
      - ${APP_FOLDER}:/var/www
    expose:
      - "8081"
    #command: bash -c "yarn install && yarn encore dev --watch"
    networks:
      - traefik

networks:
  traefik:
    external: true

When I up the first one, everything is ok, I can access it via site1.localhost for example When I up the second one, and I access site2.localhost, one time out of two I am on the right site, the other time I am on the "site1" container...

If I reverse the order of launching the "up", it is always my second site which alternates...

Do you have an idea ? I don't understand...

Use docker inspect and docker service inspect to check if the templating was done correctly.

Note that some browsers will resolve any *.localhost to 127.0.0.1, even if it is not or differently set in hosts file.

1 Like

Hi Bluepuma77,

Thanks for reply.

Docker inspect (site1-nginx site1-php site2-nginx site2-php seems good)... All directory are good...
I change to *.local just for testing, it's similar... I don't understand...