Custom Docker Network

I can’t for the life of me work out my Nextcloud will not work when it assigned to a custom docker network. I want to have it be able to connect to my MariaDB container without having to open a port and use the host IP.

If I just leave it connected to the default network and set

MYSQL_HOST=192.168.0.10:3306

it works, but if I add it to the custom docker network I am using

networks:
   - t2_proxy

so I can use MYSQL_HOST=mariadb, like I do with every other one of my services, I can’t access Nextcloud, and there are no errors in the docker log so I have no idea why it doesn’t work.

I already have a working Nextcloud install but it uses the Linuxserver image, and they replaced Apache with NGINX, but I would rather use the official image if possible.

Hello @Stuntard :handshake:

Welcome to the wonderful world of Nextcloud and it’s amazing community.

Your question is more about Docker networking rather Nextcloud. Please familiarize yourself with the the technology. Especially if you you docker compose (and would recommend to) you get “free” application network for every compose file. all containers defined in one compose file can access each other by just using service: name or optional container_name: Networking in Compose | Docker Documentation.

Take a look at examples provided by Nextcloud docker developers.

common practice in containers is to send logs to STDOUT which you can consult using "docker logs <container name>"

/wwe

I am already using Docker Compose. I have over 30 services working together flawlessly. I use custom networks for container isolation so that only containers that can talk to each other directly can do so. This is common docker practice.

As I said before, the official Nextcloud image works, but the only way I can get it to connect to my database container is if I map a port to the host for the mariadb container and connect via IP:Port which defeats one of the main purposes of docker. If I put Nextcloud on the same custom docker network as my database so it can refer to it by container name, it does not work.

The Linuxserver Nextcloud image works fine if used in the same way, but it does not use Apache, but Nginx instead.

Also there is no errors in the docker log for the Nextcloud container, I just can’t open Nextcloud in my browser. The log output is identical to how it appears if I don’t user a custom Network

Could not reliably determine the server's fully qualified domain name, using 172.29.0.3

as opposed to

Could not reliably determine the server's fully qualified domain name, using 192.168.90.10

The customer network is defined as

networks:
  t2_proxy:
    name: t2_proxy
    driver: bridge
    ipam:
      config:
        - subnet: 192.168.90.0/24

I’m running 3 instances of Nextcloud using below logic for years:

version: "3.3"

services:
  dev-nextcloud-db:
    image: mariadb:10.5
    container_name: dev-nextcloud-db
...
    env_file:
      - ./db.env

  dev-nextcloud-app:
    image: nextcloud:${NEXTCLOUD_VERSION}
...
    env_file:
      - ./nextcloud.env
      - ./db.env
    networks:
      - traefik_proxy
      - default

where db.env holds DB related env variables:

MYSQL_HOST=dev-nextcloud-db
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
MYSQL_PASSWORD=verysecurepassword!!!!

the difference I don’t assign custom network to a DB and rather use “default” network for app<->DB communication as there is no reason for me to expose the DB to any other application then Nextcloud (with additional push and cron containers skipped above for simplicity).

This setup is common and definitely works… please provide your docker-compose.yaml, docker network lsdocker network inspectand docker inspect and docker inspect app`

My Docker Compose file is over 2000 lines long so I’m only posting what is relevant.

In mariadb section, <<: *common-keys-core adds

restart: unless-stopped
    networks:
      - t2_proxy

docker-compose.yml

version: "3.9"

networks:
  t2_proxy:
    name: t2_proxy
    driver: bridge
    ipam:
      config:
        - subnet: 192.168.90.0/24
mariadb:
    <<: *common-keys-core # See EXTENSION FIELDS at the top
    container_name: mariadb
    image: linuxserver/mariadb:latest
    ports:
      - "$MARIADB_PORT:3306"
    volumes:
      - $DOCKERDIR/appdata/mariadb/data:/config
      - /etc/TZ:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    environment:
      - PUID=$PUID
      - PGID=$PGID
      - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password # Not taking this pw during initialization
    secrets:
      - mysql_root_password
nextcloud:
    image: nextcloud:latest
    container_name: nextcloud
    restart: unless-stopped
    networks:
      - t2_proxy
    environment:
      - MYSQL_HOST=mariadb
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=verysecurepassword!!!!
   volumes:
      - $DOCKERDIR/appdata/nextcloud:/var/www/html

If I remove Nextcloud from the t2_proxy network, it works, but then I have to open the port for the mariadb container and connect to it by host_ip:port which I don’t want to do. As soon as I add it back, it doesn’t work. No errors in ‘docker logs -f nextcloud’ at all, the page just doesn’t load. It has to have something to do with Apache.

On default network. Nextcloud loads
Could not reliably determine the server's fully qualified domain name, using 172.29.0.3

On t2_proxy network. Nextcloud doesn’t work
Could not reliably determine the server's fully qualified domain name, using 192.168.90.10

No issues with Linuxserver’s Nginx Nextcloud container and exactly the same setup, apart from the Photos app being busted in 26.0.1 but that’s not their issue.

nothing wrong with it… but you know you don’t need to put everything into one file? separating applications into different compose files makes administration on single applications far easier…

absolutely right… default docker subnets are in 172.x.x.x range and your t2_network defines 192.186.90.0/24 range…

based on what you posted this makes no sense… but unfortunately you didn’t post what I asked for so no idea what are doing wrong.

I’m sorry don’t get the point - you talk all the time about DB issues and now the problem must be related to Apache? please try to describe the issue exact and post logs and error messages… maybe you should start telling what you mean when you say “it works” and what is in your eyes the error!