0

Service phpyMyAdmin can't connect to db (connection refused). But as soon as I add the the same networks (default and traefik) to the db service, it starts working.

Why? For what I understand right now both share the same implicit default network. Ideed:

[
    {
        "Name": "wikiiosystemsit_default",
        "Id": "62eab0cee810c380c3b494f9a7fa4db9ed485ea002d70de4cb2fcfb7ea94f84c",
        "Created": "2024-12-12T23:49:31.56548723Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.19.0.0/16",
                    "Gateway": "172.19.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "4276e2b6bdc18f45d475ede7408feb79fe542205b23cc0ec36a61db88c3a2f90": {
                "Name": "wikiiosystemsit-phpmyadmin",
                "EndpointID": "9c73dbf36dfcd5492bd418b5288e00b6ad57b2a29ea6bf07fed1cc427e47ff89",
                "MacAddress": "02:42:ac:13:00:03",
                "IPv4Address": "172.19.0.3/16",
                "IPv6Address": ""
            },
            "d9a61504b1c97fd6fee155d61b1fa08cf0b62ba7261659a8d96f3f21ba015390": {
                "Name": "wikiiosystemsit-db",
                "EndpointID": "228d54ab65734bb3283ec6018e5c321846d59cf5c9bf9637e23dd3719d7749ee",
                "MacAddress": "02:42:ac:13:00:02",
                "IPv4Address": "172.19.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.config-hash": "968eb6d395e1f23e415b8a7f99cc736629616b1cf3cc507ca678097b776fb609",
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "wikiiosystemsit",
            "com.docker.compose.version": "2.31.0"
        }
    }
]

My Compose file:

services:
    db:
        container_name: ${COMPOSE_PROJECT_NAME}-db
        image: mariadb:11
        volumes:
            - db-data:/var/lib/mysql
        environment:
            MARIADB_USER: ${DATABASE_USER:?}
            MARIADB_PASSWORD: ${DATABASE_PASSWORD:?}
            MARIADB_DATABASE: ${DATABASE_NAME:?}
            MARIADB_ROOT_PASSWORD: ${DATABASE_ROOT_PASSWORD:?}
            TZ: ${TZ:-Europe/Rome}
        # Uncomment and this will work
        #networks:
        #    - default
        #    - traefik
        restart: unless-stopped

    phpmyadmin:
        container_name: ${COMPOSE_PROJECT_NAME}-phpmyadmin
        image: phpmyadmin:latest
        environment:
            PMA_ARBITRARY: true
            PMA_HOST: db
            UPLOAD_LIMIT: 10M
            TZ: ${TZ:-Europe/Rome}
        networks:
            - default
            - traefik
        restart: unless-stopped

volumes:
    db-data:

networks:
    traefik:
        external: true
4
  • I can't reproduce this behavior. Your compose file works fine for me exactly as written. Once services are up, I can log into phpmyadmin using the values for MARIADB_USER and MARIADB_PASSWORD. Commented Dec 13, 2024 at 0:55
  • Can you post the docker network inspec output? Commented Dec 13, 2024 at 8:03
  • Here you'll find my compose file and the output of docker container inspect for all the containers, docker network inspect for the default network, and the output from docker compose up. Commented Dec 13, 2024 at 12:05
  • Thank you @larsks for yor time. Turns out it was another misconfigured db service (see my answer). Commented Dec 13, 2024 at 23:55

1 Answer 1

0

I finally discovered what the problem was.

There was another service named "db" (in a different Compose project) on the Traefik network. As a result, phpMyAdmin, being on the Traefik network, couldn't establish a connection (and, on top of that, the other "db" was a PostgreSQL service).

Removing the Traefik network from the PostgreSQL service solved the issue.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.