basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    A service’s networks list replaces the default network

    As soon as a service has a networks: list, compose connects it only to the listed networks, and the service leaves the stack’s default network. Add the proxy network for Traefik, and the service stops seeing the database that stayed on default. List every network the service should be on.

    What it looks like

    services:
      umami:
        environment:
          - DATABASE_URL=postgresql://umami:${DB_PASSWORD}@db:5432/umami
        networks: [proxy]          # now umami is only on proxy
    
      db:
        image: postgres:16-alpine  # no list of its own — db is on umami_default
    
    networks:
      proxy:
        external: true

    While a service has no networks:, compose puts it on the stack network <project>_default. The list replaces it: umami ends up only on proxy, and db stays on umami_default. There’s no shared network, and Docker’s built-in DNS answers the name db only to network neighbors — umami isn’t one anymore.

    How to fix it

    If the database needs a way out, or you don’t want to change the layout, put default back in the list:

        networks: [default, proxy]

    There’s no need to declare default at the bottom of the file: compose creates that network itself.

    If the database doesn’t need a way out, create a network with internal: true for the service and the database: both get lists, the layout is visible right in the file, and the database stays without internet access (Docker networks).

    If it doesn’t work

    The service got the proxy network and stopped finding the database: could not translate host name "db" to address

    Cause
    The service left the default network, and the database stayed on it: they no longer share a network.
    Fix
    networks: [default, proxy] on the service — or a separate internal network for it and the database (Docker networks).

    How to check

    docker inspect umami-umami-1 --format '{{range $k, $v := .NetworkSettings.Networks}}{{$k}} {{end}}'
    # proxy umami_default

    Both networks are in place — db resolves by name again.