Search code examples
dockerdocker-composerclone

Content of docker bind mount is not showing inside the container


EDITED:

Rclone has a bucket mounted to the host directory /home/user/rclone. I want to access the contents of this directory inside nextcloud docker instance. So I would bind mount it to /var/www/html/data. With the option shared, any changes made in the container will be reflected in the host, and vice versa.

I have set the permission of /home/user/rclone to be 777. And the content is visible with a ls command from the host. Once the docker container is restarted, a ls command from within the container does not show any files. Rclone is still running properly.

I am suspecting that because the volume nextcloud is mounted at /var/www/html, the mount of the bind mount at /var/www/html/data is covered up.

So then I picked another directory inside the container, namely /mnt and tried it. Still no files show up with a ls command.

My nextcloud docker compose: (mysql does not have anything to do with this; showing the /var/www/html/data mount version only.)

version: '2'

volumes:
  nextcloud:
  db:

services:
  db:
    image: mariadb
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=xxx
      - MYSQL_PASSWORD=xxx
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    network_mode: npm_default
    container_name: db

  app:
    image: nextcloud:latest
    restart: always
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
      - /home/user/rclone:/var/www/html/data:shared
    environment:
      - MYSQL_PASSWORD=xxx
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db
      - NEXTCLOUD_TRUSTED_DOMAINS=xxx
    network_mode: npm_default
    container_name: nextcloud

Another way of putting it:

rclone cloud storage --> host --> —> docker —-> nextcloud external storage


Solution

  • So the reason why the nextcloud service cannot view the content is due to permission problems.

    If you do exec -it nextcloud bash to check the contents, they are there because you are root.

    So the proper solution if you want to use a shared bind mount with the host directory, is to set permission to 666 so the others in the container can view the file.

    But at the end, I have figured that volume plugins are a way better solution, thus this is somewhat deprecated.