Nextcloud AIO + Traefik

Nextcloud AIO + Traefik

I already have Nextcloud installed through running multiple containers, but recentlyI heard that Nextcloud AIO is the official solution so I tried to migrate to it.

The issue was when trying to set up Traefik v3. By default I use Traefik labels with all my services in my homelab so I tried it with nextcloud aio but it didn’t work, as this container runs multiple containers behind it. Then I looked into your portal and found and old tutorial using Traefik v2, that hardcoded the services in the traefik config file.

Could you please update the documentation on Traefik v3 and explain how to set it up by Traefik labels to dynamically configure it?

Thanks,

Best regards.

I think multiple containers is still generally better if you know what you’re doing which you appear to do.

It allows you to break apart the services to separate components at least. I use Caddy rather than Traefik and use the nextcloud:apache image so I don’t have to deal with redoing the FPM logic and the apache image is good enough for it.

My architecture looks like this and NextCloud Web App, and Imaginary can be scaled horizontally as well.

This isn’t a v2 versus v3 thing. As noted in the AIO documentation, Traefik labels don’t work with AIO. AIO orchestrates its own containers.

As for v2 to v3, feel free to submit a PR against the AIO Reverse Proxy Documentation if you wish based on:

1 Like

So, I’ve been doing a lot of troubleshooting the past couple days, and I have come across this rhetoric a lot, that “AIO and Traefik labels are incompatible”.

I would like to respectfully disagree.

I am using Portainer Stacks. Here is my compose/stack file. I have taken the compose example for AIO and replicated the Traefik behaviour as per the reverse proxy documentation for Traefik v2.

After initializing the stack, I entered the domain at the port 8999 interface. Since the verification was disabled, it accepted to the next interface. Once there I downloaded and launched the rest of the containers.

Once the containers spun up, since the Traefik instance is preemptively pointing to this http://nextcloud-aio-apache:11000, it connected.

I am very open to hear “reasons why this will break”. For the moment, I am not seeing any. The Traefik interface is showing the configuration I expect to see :person_shrugging:.

services:
  nextcloud-aio-mastercontainer:
    image: ghcr.io/nextcloud-releases/all-in-one:latest
    init: true
    env_file:
      - stack.env
    restart: always
    container_name: nextcloud-aio-mastercontainer # This line is not allowed to be changed as otherwise AIO will not work correctly
    volumes:
      - nextcloud_aio_mastercontainer:/mnt/docker-aio-config # This line is not allowed to be changed as otherwise the built-in backup solution will not work
      - /var/run/docker.sock:/var/run/docker.sock:ro # May be changed on macOS, Windows or docker rootless. See the applicable documentation. If adjusting, don't forget to also set 'WATCHTOWER_DOCKER_SOCKET_PATH'!
    #network_mode: bridge # add to the same network as docker run would do
    networks:
      - frontend
    labels: # Traefik config
      - traefik.enable=true

      - traefik.http.routers.${SUBDOMAIN}-https.tls=true
      - traefik.http.routers.${SUBDOMAIN}-https.tls.certresolver=cloudflare
      - traefik.http.routers.${SUBDOMAIN}-https.entrypoints=websecure
      - traefik.http.routers.${SUBDOMAIN}-https.rule=Host(`${SUBDOMAIN}.mydomain.ca`)
      - traefik.http.services.${SUBDOMAIN}-https.loadbalancer.server.url=http://nextcloud-aio-apache:11000
      - traefik.http.middlewares.nc-redirect.redirectscheme.scheme=https
      - traefik.http.middlewares.nc-secure-headers.headers.hostsProxyHeaders=X-Forwarded-Host
      - traefik.http.middlewares.nc-secure-headers.headers.referrerPolicy=same-origin
      - traefik.http.middlewares.nc-chain.chain.middlewares=nc-redirect,nc-secure-headers
      - traefik.http.routers.${SUBDOMAIN}-https.middlewares=nc-chain
    ports:
    #  - 80:80 # Can be removed when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else). See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      - 8999:8080
    #  - 8443:8443 # Can be removed when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else). See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
    environment: # Is needed when using any of the options below
      # AIO_DISABLE_BACKUP_SECTION: false # Setting this to true allows to hide the backup section in the AIO interface. See https://github.com/nextcloud/all-in-one#how-to-disable-the-backup-section
      APACHE_PORT: 11000 # Is needed when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else). See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      APACHE_IP_BINDING: 0.0.0.0 # Should be set when running behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else) that is running on the same host. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      APACHE_ADDITIONAL_NETWORK: frontend # (Optional) Connect the apache container to an additional docker network. Needed when behind a web server or reverse proxy (like Apache, Nginx, Caddy, Cloudflare Tunnel and else) running in a different docker network on same server. See https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md
      # BORG_RETENTION_POLICY: --keep-within=7d --keep-weekly=4 --keep-monthly=6 # Allows to adjust borgs retention policy. See https://github.com/nextcloud/all-in-one#how-to-adjust-borgs-retention-policy
      # COLLABORA_SECCOMP_DISABLED: false # Setting this to true allows to disable Collabora's Seccomp feature. See https://github.com/nextcloud/all-in-one#how-to-disable-collaboras-seccomp-feature
      # FULLTEXTSEARCH_JAVA_OPTIONS: "-Xms1024M -Xmx1024M" # Allows to adjust the fulltextsearch java options. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-fulltextsearch-java-options
      # NEXTCLOUD_DATADIR: /data # Allows to set the host directory for Nextcloud's datadir. ⚠️⚠️⚠️ Warning: do not set or adjust this value after the initial Nextcloud installation is done! See https://github.com/nextcloud/all-in-one#how-to-change-the-default-location-of-nextclouds-datadir
      # NEXTCLOUD_MOUNT: /mnt/ # Allows the Nextcloud container to access the chosen directory on the host. See https://github.com/nextcloud/all-in-one#how-to-allow-the-nextcloud-container-to-access-directories-on-the-host
      # NEXTCLOUD_UPLOAD_LIMIT: 16G # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-upload-limit-for-nextcloud
      # NEXTCLOUD_MAX_TIME: 3600 # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-max-execution-time-for-nextcloud
      # NEXTCLOUD_MEMORY_LIMIT: 512M # Can be adjusted if you need more. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-php-memory-limit-for-nextcloud
      # NEXTCLOUD_TRUSTED_CACERTS_DIR: /path/to/my/cacerts # CA certificates in this directory will be trusted by the OS of the nextcloud container (Useful e.g. for LDAPS) See https://github.com/nextcloud/all-in-one#how-to-trust-user-defined-certification-authorities-ca
      # NEXTCLOUD_STARTUP_APPS: deck twofactor_totp tasks calendar contacts notes # Allows to modify the Nextcloud apps that are installed on starting AIO the first time. See https://github.com/nextcloud/all-in-one#how-to-change-the-nextcloud-apps-that-are-installed-on-the-first-startup
      # NEXTCLOUD_ADDITIONAL_APKS: imagemagick # This allows to add additional packages to the Nextcloud container permanently. Default is imagemagick but can be overwritten by modifying this value. See https://github.com/nextcloud/all-in-one#how-to-add-os-packages-permanently-to-the-nextcloud-container
      # NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS: imagick # This allows to add additional php extensions to the Nextcloud container permanently. Default is imagick but can be overwritten by modifying this value. See https://github.com/nextcloud/all-in-one#how-to-add-php-extensions-permanently-to-the-nextcloud-container
      # NEXTCLOUD_ENABLE_DRI_DEVICE: true # This allows to enable the /dev/dri device for containers that profit from it. ⚠️⚠️⚠️ Warning: this only works if the '/dev/dri' device is present on the host! If it should not exist on your host, don't set this to true as otherwise the Nextcloud container will fail to start! See https://github.com/nextcloud/all-in-one#how-to-enable-hardware-acceleration-for-nextcloud
      # NEXTCLOUD_ENABLE_NVIDIA_GPU: true # This allows to enable the NVIDIA runtime and GPU access for containers that profit from it. ⚠️⚠️⚠️ Warning: this only works if an NVIDIA gpu is installed on the server. See https://github.com/nextcloud/all-in-one#how-to-enable-hardware-acceleration-for-nextcloud.
      # NEXTCLOUD_KEEP_DISABLED_APPS: false # Setting this to true will keep Nextcloud apps that are disabled in the AIO interface and not uninstall them if they should be installed. See https://github.com/nextcloud/all-in-one#how-to-keep-disabled-apps
      SKIP_DOMAIN_VALIDATION: true # This should only be set to true if things are correctly configured. See https://github.com/nextcloud/all-in-one?tab=readme-ov-file#how-to-skip-the-domain-validation
      # TALK_PORT: 3478 # This allows to adjust the port that the talk container is using which is exposed on the host. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-talk-port
      # WATCHTOWER_DOCKER_SOCKET_PATH: /var/run/docker.sock # Needs to be specified if the docker socket on the host is not located in the default '/var/run/docker.sock'. Otherwise mastercontainer updates will fail. For macos it needs to be '/var/run/docker.sock'
    # security_opt: ["label:disable"] # Is needed when using SELinux

#   # Optional: Caddy reverse proxy. See https://github.com/nextcloud/all-in-one/discussions/575
#   # Alternatively, use Tailscale if you don't have a domain yet. See https://github.com/nextcloud/all-in-one/discussions/5439
#   # Hint: You need to uncomment APACHE_PORT: 11000 above, adjust cloud.example.com to your domain and uncomment the necessary docker volumes at the bottom of this file in order to make it work
#   # You can find further examples here: https://github.com/nextcloud/all-in-one/discussions/588
#   caddy:
#     image: caddy:alpine
#     restart: always
#     container_name: caddy
#     volumes:
#       - caddy_certs:/certs
#       - caddy_config:/config
#       - caddy_data:/data
#       - caddy_sites:/srv
#     network_mode: "host"
#     configs:
#       - source: Caddyfile
#         target: /etc/caddy/Caddyfile
# configs:
#   Caddyfile:
#     content: |
#       # Adjust cloud.example.com to your domain below
#       https://cloud.example.com:443 {
#         reverse_proxy localhost:11000
#       }
networks:
  frontend:
    external: true

volumes: # If you want to store the data on a different drive, see https://github.com/nextcloud/all-in-one#how-to-store-the-filesinstallation-on-a-separate-drive
  nextcloud_aio_mastercontainer:
    name: nextcloud_aio_mastercontainer # This line is not allowed to be changed as otherwise the built-in backup solution will not work
  # caddy_certs:
  # caddy_config:
  # caddy_data:
  # caddy_sites:
1 Like

You are right. I think we didnt consider this as a possibility to point at a different container when creating the documentation. Would you mind updating the docs to reflect this?

1 Like

thanks for the quick response and also all the other people, great community here.

However, I found a problem when deploying this, I don’t see in Traefik the url that you set but the docker IP of my master container instead of the apache one. I attach a picture of it.
It seems that Traefik is correctly reading the labels, but ignoring the one where you set the url. Do I need to reconfigure something in Traefik?

Thanks in advance.

There’s not much to do on the Traefik compose or traefik.yaml side. I am using a pretty basic setup with CloudFlare certs and “frontend” network set up through Portainer. The entirety of the router, service and middleware is created with those labels.

The label that points the service to the Apache container is here:

traefik.http.services.${SUBDOMAIN}-https. loadbalancer.server.url=http://nextcloud-aio- apache:11000

And just to reiterate, this will point to nothing until the Apache container has been created. Also, you can completely ignore the “domaincheck” container.

I’ll try my best to remember to submit a change to the docs :blush:

1 Like