NextCloud in Docker after set the hostpath in volumes nextcloud server can not work

Hi, I’m a student who want to build a private storage cloud, my test OS is Ubuntu 20.04. here’s my problem:
When I use official .yml file and change DB to the mysql, and set the external path in db’s volumes, it can work. like this:

version: '3'

volumes:
  nextcloud:
  db:

services:
  db:
    image: mysql
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - ~/docker/mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=12345678
      - MYSQL_PASSWORD=nextcloud
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  app:
    image: nextcloud
    restart: always
    ports:
      - 8080:80
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MYSQL_PASSWORD=nextcloud
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db

but when I want to set the hostpath on the app’s volumes, the server can not work, and show
the message like this:

  app:
    image: nextcloud
    restart: always
    ports:
      - 8080:80
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
      - ./app/data:/var/www/html/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MYSQL_PASSWORD=nextcloud
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db

how to give the webserver write access to the root directory?
My final gold is to set the app’s volumes like this:

  app:
    image: nextcloud
    restart: always
    ports:
      - 8080:80
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
      - ./app:/var/www/html
      - ./app/config:/var/www/html/config
      - ./app/custom_apps:/var/www/html/custom_apps
      - ./app/data:/var/www/html/data
      - ./app/themes:/var/www/html/themes
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MYSQL_PASSWORD=nextcloud
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db

Thank you & Best Regards!

you have to chown the folder ./app to belong to the webserver user in the container.

to get the id of the webserver user inside the container try:

sudo docker exec -u www-data nextcloud id

and than use this uid/gid to change ./app

ok?

this won’t work. /var/www/html is double.

1 Like

Hi, thanks for your reply,
Now is working.
I have follow your step, and use the command below on the host:

sudo chown -R www-data:www-data ./app

There have some note I want to share,
this is fits for someone who want to build a new nextcloud system with docker.
the volumes i connect to the host folder is all empty in the beginning,
and every time i run up my container with customize volumes(in docker-compose.yml),
it always wrong,

to solve this problem,

  1. Run up nextcloud container without customize volumes (in docker-compose.yml),
  2. use docker cp <containerId>:/file/path/in/container/file /host/local/path/file to cp all the files/floder u want, in my case i use this:
docker cp <containerId>:/var/www/html/<floders-i-want-use-volumes>/ ./app/
  1. Change ./app permission.
sudo chown -R www-data:www-data ./app
  1. Run up nextcloud container with customize volumes (in docker-compose.yml).
  2. Done!!

Hope it can help someone who met the same problem with me, enjoy~~~