linuxserver / docker-unifi-network-application

GNU General Public License v3.0
551 stars 40 forks source link

[BUG] unifi-app does not connect to database container if attached to two networks #79

Closed schuettecarsten closed 5 days ago

schuettecarsten commented 3 months ago

Is there an existing issue for this?

Current Behavior

I am using docker compose to deploy two containers: app and db. I also have two networks, one "macvlan" network and an "internal" network. The "app" container is attached to both networks and should be reachable from an public IP, e.g. 192.168.11.2, and then it should use the internal network to communicate with the mongodb container. Unfortunately, that does not work.

Expected Behavior

No response

Steps To Reproduce

Here are the relevant parts of the docker-compose.yml file:

services:
  unifi-app:
    image: lscr.io/linuxserver/unifi-network-application:latest
    container_name: unifi-app
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - MONGO_USER=unifi
      - MONGO_PASS=***
      - MONGO_HOST=unifi-db
      - MONGO_PORT=27017
      - MONGO_DBNAME=unifi-db
    volumes: [default]
    ports: [default]
    depends_on:
      - unifi-db
    restart: unless-stopped
    networks:
      internal:
      vlan1:
        ipv4_address: 192.168.11.2
  unifi-db:
    image: docker.io/mongo:4.4.18
    container_name: unifi-db
    volumes:
      - /opt/data/unifi/db:/data/db
      - /opt/data/unifi/db-config:/data/configdb
      - /opt/data/unifi/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
    restart: unless-stopped
    networks:
      internal:
networks:
  internal:
    name: internal
    internal: true
  vlan1:
    name: vlan1
    driver: macvlan
    driver_opts:
      parent: vlan1
    ipam:
      config:
        - subnet: 192.168.11.0/24
          gateway: 192.168.11.1

system.properties:

db.mongo.uri=mongodb\://unifi\:unifi123\!@unifi-db\:27017/unifi-db?tls\=false
statdb.mongo.uri=mongodb\://unifi\:unifi123\!@unifi-db\:27017/unifi-db_stat?tls\=false
unifi.db.name=unifi-db

server.log:

[2024-03-21 21:30:27,614] <launcher> INFO  db     - Connecting to mongodb://unifi:unifi123!@unifi-db:27017/unifi-db?tls=false
[2024-03-21 21:30:28,288] <launcher> INFO  db     - db connection established...
[2024-03-21 21:30:38,819] <launcher> INFO  db     - db connection established...
[2024-03-21 21:30:49,321] <launcher> INFO  db     - db connection established...
[2024-03-21 21:30:59,824] <launcher> INFO  db     - db connection established...
[2024-03-21 21:31:10,326] <launcher> INFO  db     - db connection established...
[2024-03-21 21:31:20,828] <launcher> INFO  db     - db connection established...
[2024-03-21 21:31:31,331] <launcher> INFO  db     - db connection established...
[2024-03-21 21:31:41,833] <launcher> INFO  db     - db connection established...
[2024-03-21 21:31:52,335] <launcher> INFO  db     - db connection established...
[2024-03-21 21:32:02,837] <launcher> INFO  db     - db connection established...
[2024-03-21 21:32:13,341] <launcher> INFO  db     - db connection established...
[2024-03-21 21:32:23,843] <launcher> INFO  db     - db connection established...
[2024-03-21 21:32:34,346] <launcher> INFO  db     - db connection established...
[2024-03-21 21:32:44,848] <launcher> INFO  db     - db connection established...
[2024-03-21 21:32:55,350] <launcher> INFO  db     - db connection established...
[2024-03-21 21:33:05,852] <launcher> INFO  db     - db connection established...
[2024-03-21 21:33:16,353] <launcher> INFO  db     - db connection established...
[2024-03-21 21:33:26,855] <launcher> INFO  db     - db connection established...
[2024-03-21 21:33:37,357] <launcher> INFO  db     - db connection established...

If I configure it that way, the app gets stuck on connecting to database. To fix it, I have to connect the unifi-db container to vlan1 network and assign a static IP from 192.168.11.0/24 subnet.

Environment

Raspberry PI 4 B+

CPU architecture

arm64

Docker creation

docker-compose.yml, see steps to reproduce

Container logs

root@GatewayDummi:~# docker logs unifi-app
[migrations] started
[migrations] no migrations found
───────────────────────────────────────

      ██╗     ███████╗██╗ ██████╗
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝

   Brought to you by linuxserver.io
───────────────────────────────────────

To support LSIO projects visit:
https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    1000
User GID:    1000
───────────────────────────────────────

[custom-init] No custom files found, skipping...
github-actions[bot] commented 3 months ago

Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.

Roxedus commented 3 months ago

Check which DNS server is used in the container.

schuettecarsten commented 3 months ago

DNS looks fine, there is no dns option in the docker-compose.yml, so I did not overwrite DNS settings.

root@dummi:/etc/docker# docker exec -ti unifi-app cat /etc/resolv.conf
search guest
nameserver 127.0.0.11
options ndots:0
root@dummi:/etc/docker# docker exec -ti unifi-app getent hosts unifi-db
172.23.0.2      unifi-db

Here is output of docker inspect internal with details of the internal network:

[
    {
        "Name": "internal",
        "Id": "f88f8303f92de85e729e111bbea2fc20aa45149d09888c48495b51f7fe3f1e7d",
        "Created": "2024-03-22T06:56:21.447768207Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.23.0.0/16",
                    "Gateway": "172.23.0.1"
                }
            ]
        },
        "Internal": true,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "18194943a40177b0dc3804883c4059fb333b36555a38d52f185a27e9c6371fcc": {
                "Name": "unifi-app",
                "EndpointID": "96343f96434bb0996f80912128dd5016a396fea331e4f3462d7e86291970b3dc",
                "MacAddress": "02:42:ac:17:00:03",
                "IPv4Address": "172.23.0.3/16",
                "IPv6Address": ""
            },
            "7c6aa7fbc638f18e3f1f8af7d51349a9f77e74bf3a3abc593f0ee1d89d604965": {
                "Name": "unifi-db",
                "EndpointID": "b529243dd226e8cd6620b6676e1981d225cb7017fec6e63164ba8209bac3c8c2",
                "MacAddress": "02:42:ac:17:00:02",
                "IPv4Address": "172.23.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "internal",
            "com.docker.compose.project": "docker",
            "com.docker.compose.version": "2.25.0"
        }
    }
]
j0nnymoe commented 3 months ago

If you remove your vlan network, will unifi connect to the database?

schuettecarsten commented 3 months ago

That's interesing. No, it does not.

LinuxServer-CI commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.