Wrong container network IP used randomly on TCP routing

CONTEXT

We are trying to use Traefik with docker-compose too enable automatic domain name routing.

You can see the open-source project here: https://gitlab.com/nexylan/templates/symfony-website

ISSUE

On a single host server, we did install traefik with this configuration:

version: "3.7"

# Should be installed manually or with a dedicated project
services:
  router:
    image: traefik:2.0
    container_name: nexylan_symfony-website_router
    command:
      - --accesslog=true
      - --api.insecure=true
      - --providers.docker=true
      - --providers.docker.exposedByDefault=false
      - --providers.docker.network=router
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    ports:
      - 80:80
      - 8080:8080
    restart: always
    networks:
      - router

networks:
  router: ~

Then, we do a automatic deploy with GitLab CI and this configuration:

docker-compose.yml:

version: "3.7"

services:
  app:
    image: ${IMAGE_NAME}:${IMAGE_TAG}
    build:
      context: .
      target: ${APP_ENV}
      cache_from:
        - ${IMAGE_NAME}:${IMAGE_TAG}
      args:
        APP_ENV: ${APP_ENV}
        USER: ${USER:-root}
    command: /run.sh
    environment:
      - APP_TITLE
      - APP_VERSION
      - APP_ENV
    depends_on:
      - db

  db:
    image: bitnami/mysql:5.7-debian-9
    environment:
      - ALLOW_EMPTY_PASSWORD=yes

  test:
    image: alpine
    command: echo "TODO"

stack.yml:

version: "3.7"

services:
  app:
    networks:
      - default
      - router
    labels:
      - traefik.enable=true
      - traefik.http.routers.app-${CI_PROJECT_PATH_SLUG}-${CI_COMMIT_REF_NAME}.rule=Host(`${CI_ENVIRONMENT_HOST}`)

networks:
  router:
    external:
      name: root_router

With master deploy and a merge request named foo, we now have 3 networks:

  • root_router: 172.24.0.*
  • app-master: 172.25.0.*
  • app-nginx: 172.26.0.*

According to the configuration, Traefik should always route the traffic on 172.24.0.*.
But sometimes, Traefik will route the traffic to the app networks (25/26).

I can see the router and the app containers on the root_router:

        "Containers": {
            "4c57f922b92600f3a617e9ef3f8e7b9812c11b203a6b8e901aff982d16ead00b": {
                "Name": "nexylan-templates-symfony-website_master_app_1",
                "EndpointID": "f1099fe15b47ecfd1f277095168622ae1c90c6c0bf9a64eec4efa1e557d12a3f",
                "MacAddress": "02:42:ac:18:00:04",
                "IPv4Address": "172.24.0.4/16",
                "IPv6Address": ""
            },
            "9e6f24d8decdc46c3c6c91a390da2a0ce84ea7f2ec7363045b4fbcdaf0d32758": {
                "Name": "nexylan-templates-symfony-website_mysql-wait_app_1",
                "EndpointID": "ae4a54bdc98db39273633bb60e7cc567f70e9630af86f1054ed42d2cc469849a",
                "MacAddress": "02:42:ac:18:00:03",
                "IPv4Address": "172.24.0.3/16",
                "IPv6Address": ""
            },
            "e9ce3b9bee77c05c1bc7852dac5f3bff0cf85e3f762060b0fff841565198af25": {
                "Name": "nexylan_symfony-website_router",
                "EndpointID": "c74464b6b366bda39921838aa153498d026cbe3815ebca73be0b6dc41b628173",
                "MacAddress": "02:42:ac:18:00:02",
                "IPv4Address": "172.24.0.2/16",
                "IPv6Address": ""
            }

How to stick Traefik to use 172.24. ip address from the common network and avoid timeout?

Thanks