docker icon indicating copy to clipboard operation
docker copied to clipboard

Trick to run docker nextcloud fpm with nginx in a sub directory

Open chen-xin opened this issue 2 years ago • 2 comments

The official nextcloud fpm image is great but it does not support mounting to a sub directory. It took me two long days to find this trick, record here for someone might need:

  1. Compose for initialize. Note: navigate to https://my.site/nextcloud now will raise 404:
services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx1
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/certs:/etc/ssl/nginx
        # - ${DATA_VOLUME}/www:/www
        # - ${DATA_VOLUME}/nextcloud:/www/nextcloud
      - ${DATA_VOLUME}/www:/var/www/html
      - ${DATA_VOLUME}/nextcloud:/var/www/html/nextcloud
    restart: unless-stopped

  nextcloud:
    image: nextcloud:fpm-alpine
    container_name: nextcloud1
    restart: unless-stopped
      # ports:
      # - 9000:9000
    volumes:     
      - ${DATA_VOLUME}/nextcloud:/var/www/html
      # use the following config instead of above after nextcloud initialized itself:
      # - ${DATA_VOLUME}/nextcloud:/var/www/html/nextcloud 
  1. Modify last line of compose file as comments and restart containers. Note: use the modified version BEFORE initialize will cause cannot delete non-empty directory: nextcloud.

chen-xin avatar Feb 11 '23 14:02 chen-xin

This might be no good solution. On https://stackoverflow.com/a/49861267 i have read that Nextcloud will use rsync on /var/www/html and delete all paths unknown to base installation - so subfolder "nextcloud" and ALL CONTAINING DATA could be silently removed when updating? i have not testet that, but the right solution i would like to use is to use a nginx-proxy for that. Currently i am testing with this example: https://github.com/nextcloud/docker/tree/master/.examples/docker-compose/with-nginx-proxy/postgres/fpm but unfortunatelly had no luck to setup virtual paths.

maybe we both search for a solution at #401 ?

obel1x avatar May 27 '23 03:05 obel1x

The official nextcloud fpm image is great but it does not support mounting to a sub directory.

Do you actually need Nextcloud to be installed in a subdirectory or merely reachable via a subdirectory? If the latter, just put a reverse proxy in front. If the former, why?

joshtrichards avatar May 31 '24 20:05 joshtrichards