Deploying Nextcloud fpm with docker compose

I’m using this as a base

My architecture is the following, I’m using docker compose in Unraid (probably not relevant) but what I want is

I want to have this Nexcloud service based on the docker compose below in a VLAN, and I need to integrate the web service (nginx fpm) to be with my nginx proxy that is on another VLAN in 10.10.50.10.

So I guess that in order to achieve that I need to give an external IP (10.10.40.160) to the fpm service so it can connect with my nginx docker (not part of the compose) in another VLAN.

So based on that I did this docker compose

version: '3.8'

networks:
  br1:
    external: true
  nextcloud_network:
    driver: bridge

services:

  mariadb:
    image: mariadb:10.6
    container_name: MariaDBNC
    restart: unless-stopped
    command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
    healthcheck:
      test: ["CMD-SHELL", "mysql nextcloud -unextcloud -paaaaaaaaaaaaaa -e 'SELECT 1;'  || exit 1"]
      interval: 2s
      retries: 120
    volumes:
      - /mnt/user/Docker/Nextcloud/mariadb:/var/lib/mysql
    environment:
      - TZ=Europe/Madrid
      - MYSQL_ROOT_PASSWORD=aaaaaaaaaaaaaaaaaaa
      - MYSQL_PASSWORD=aaaaaaaaaaaaaaaaaaaa
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MARIADB_AUTO_UPGRADE=1
      - MARIADB_DISABLE_UPGRADE_BACKUP=1
    networks:
      - nextcloud_network
    dns:
      - 10.10.40.5    
    labels:
      - "com.centurylinklabs.watchtower.enable=true"

  redis:
    image: redis:alpine
    container_name: RedisNC
    restart: unless-stopped
    command: redis-server --requirepass aaaaaaaaaaaaaaa
    volumes:
      - /mnt/user/Docker/Nextcloud/redis:/data
    environment:
      - TZ=Europe/Madrid
      - PUID=1000
      - PGID=100
    networks:
      - nextcloud_network
    dns:
      - 10.10.40.5
    labels:
      - "com.centurylinklabs.watchtower.enable=true"

  nextcloud:
    image: nextcloud:fpm-alpine
    container_name: Nextcloud
    restart: unless-stopped
    depends_on:
      mariadb:
        condition: service_healthy
    volumes:
      - /mnt/user/Docker/Nextcloud/nextcloud:/var/www/html
      - /mnt/user/Media/Nextcloud:/var/www/html/data
      - type: tmpfs
        target: /tmp
        tmpfs:
          size: 1000000000
    environment:
      - TZ=Europe/Madrid
      - PUID=1000
      - PGID=100
      - UMASK=022
      - MYSQL_PASSWORD=aaaaaaaaaaaaaaaaaaa
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=mariadb
      - REDIS_HOST=redis
      - REDIS_HOST_PASSWORD=aaaaaaaaaaaaaaaaaa
    networks:
      - nextcloud_network
    dns:
      - 10.10.40.5
    labels:
      - "com.centurylinklabs.watchtower.enable=true"

  web:
    build: ./web
    container_name: nginx-fpm
    restart: always
    networks:
      nextcloud_network:
      br1:
        ipv4_address: 10.10.40.160
    ports:
      - 127.0.0.1:8080:80
    volumes:
      - /mnt/user/Docker/Nextcloud/nextcloud:/var/www/html,ro
    depends_on:
      - nextcloud

  cron:
    image: nextcloud:fpm-alpine
    container_name: CronNC
    restart: unless-stopped
    depends_on:
      - mariadb
      - redis
    volumes:
      - /mnt/user/Docker/Nextcloud/nextcloud:/var/www/html
    networks:
      - nextcloud_network
    dns:
      - 10.10.40.5
    entrypoint: /cron.sh
    labels:
      - "com.centurylinklabs.watchtower.enable=true"

This are the paths of the setup of the compose, I did it this way due to this parameter (build: ./web)

And I edited the nginx.conf like this to replace app:9000 for the nginx IP

then when I run it I get this error
nginx-fpm | nginx: [emerg] host not found in upstream “app:9000” in /etc/nginx/nginx.conf:33

nginx-fpm  | 2023/04/21 13:07:23 [emerg] 1#1: host not found in upstream "app:9000" in /etc/nginx/nginx.conf:33
nginx-fpm  | nginx: [emerg] host not found in upstream "app:9000" in /etc/nginx/nginx.conf:33
nginx-fpm  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx-fpm  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx-fpm  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx-fpm  | 10-listen-on-ipv6-by-default.sh: info: IPv6 listen already enabled
nginx-fpm  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx-fpm  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx-fpm  | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx-fpm  | 2023/04/21 13:07:49 [emerg] 1#1: host not found in upstream "**app:9000**" in /etc/nginx/nginx.conf:33
nginx-fpm  | nginx: [emerg] host not found in upstream "app:9000" in /etc/nginx/nginx.conf:33

I’m sure there are more than one thing wrong in the docker compose, but I need help

  1. Fix de docker compose
  2. Configure the other nginx configuration in the nginx docker to work with nextcloud using fpm
  3. How do I configure my nginx docker? do I need to expose port 9000 or from a network point of view what conectivity is required?

The configuration should be based on this, but not sure about the paths or any reference to the 9000 port

How should I change the configuration of nginx in 10.10.50.10 to connect it with Nextcloud using fpm?

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name nextcloud.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location / {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app nextcloud;
        set $upstream_port 443;
        set $upstream_proto https;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;

        proxy_hide_header X-Frame-Options;
        proxy_max_temp_file_size 2048m;
    }
}

hi @l0rdraiden welcome to the forum :handshake:

very good first post!

you are not wrong with your analysis. For me it looks like you are not very familiar with docker… maybe you should work through some (comprehensive) tutorial. This will likely answer the questions above…

To give you some starting points:

  • in general you don’t need (must not) configure DNS server for containers (until you exactly know what you do :wink: ) Docker has an internal DNS daemon which is very handy when it comes to inter-container communication: all containers connected to the same network can resolve each other using “service” name or container_name
  • external DNS is automatically resolved using Docker host DNS
  • the error host not found in upstream "app:9000" likely results from above - nginx wants to connect with app:9000 and can’t resolve the host “app” using DNS server 10.10.40.5
  • Ports: - 127.0.0.1:8080:80 directive is weird… you just expose the container on localhost IP (accessible only from this host?!) use - 8080:80 to expose container port 80 on port 8080 of the host (each IP)

hope this will help. again - please familiarize yourself with Docker networking concepts… maybe paint a picture of networks and connections to better understand which connection only needs to exist internally and which must be exposed to the outside.

what would be the definition of your network external br1
how do you create it ?