Search code examples
dockerdocker-composeowncloud

Docker-compose local directory mappings are ignored, docker volumes are used instead


This is my first time setting up owncloud, and I’m trying to do it using docker-compose. The YAML file that I’m using is the following:

version: "3"

services:
  owncloud:
    image: owncloud/server:latest
    container_name: owncloud_server
    restart: always
    ports:
      - 1234:8080
    depends_on:
      - mariadb
      - redis
    environment:
      - OWNCLOUD_DOMAIN=owncloud.mydomain.net
      - OWNCLOUD_DB_TYPE=mysql
      - OWNCLOUD_DB_NAME=owncloud
      - OWNCLOUD_DB_USERNAME=owncloud
      - OWNCLOUD_DB_PASSWORD=passwd
      - OWNCLOUD_DB_HOST=mariadb
      - OWNCLOUD_ADMIN_USERNAME=user-admin
      - OWNCLOUD_ADMIN_PASSWORD=passwd
      - OWNCLOUD_MYSQL_UTF8MB4=true
      - OWNCLOUD_REDIS_ENABLED=true
      - OWNCLOUD_REDIS_HOST=redis
    volumes:
      - /mnt/volume-nbg1-1/owncloud/files:/var/www/html/files
      - /mnt/volume-nbg1-1/owncloud/config:/var/www/html/config
      - /mnt/volume-nbg1-1/owncloud/apps:/var/www/html/apps
      - /mnt/volume-nbg1-1/owncloud/sessions:/var/www/html/sessions

  mariadb:
    image: mariadb:10.5
    container_name: owncloud_mariadb
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=passwd
      - MYSQL_USER=owncloud
      - MYSQL_PASSWORD=passwd
      - MYSQL_DATABASE=owncloud
    volumes:
      - /mnt/volume-nbg1-1/owncloud/mariadb:/var/lib/mysql

  redis:
    image: redis:6
    container_name: owncloud_redis
    restart: always
    volumes:
      - /mnt/volume-nbg1-1/owncloud/redis:/data

My issue is that although the Redis and MariaDB directories are created and filled correctly upon deployment, the owncloud mounted directories seem to be created correctly, but then a docker volume is also created inside /var/lib/docker/volumes/<random_seq>/_data and then the directories in it are the ones that get populated. The owncloud.log is empty, so I can’t get any hints from that. I’ve also tried changing the owner of the owncloud dir inside /mnt/volume-nbg1-1 to the docker user, but that didn’t change anything. Any ideas on what I’m doing wrong?


Solution

  • Inspecting the owncloud/server:latest image shows the volume they define in there is /mnt/data. So you'd need to define a volume for that to avoid the anonymous volume docker creates by default. E.g.:

    version: "3"
    
    services:
      owncloud:
        image: owncloud/server:latest
        container_name: owncloud_server
        restart: always
        ports:
          - 1234:8080
        depends_on:
          - mariadb
          - redis
        environment:
          - OWNCLOUD_DOMAIN=owncloud.mydomain.net
          - OWNCLOUD_DB_TYPE=mysql
          - OWNCLOUD_DB_NAME=owncloud
          - OWNCLOUD_DB_USERNAME=owncloud
          - OWNCLOUD_DB_PASSWORD=passwd
          - OWNCLOUD_DB_HOST=mariadb
          - OWNCLOUD_ADMIN_USERNAME=user-admin
          - OWNCLOUD_ADMIN_PASSWORD=passwd
          - OWNCLOUD_MYSQL_UTF8MB4=true
          - OWNCLOUD_REDIS_ENABLED=true
          - OWNCLOUD_REDIS_HOST=redis
        volumes:
          - owncloud-data:/mnt/data
          - /mnt/volume-nbg1-1/owncloud/files:/var/www/html/files
          - /mnt/volume-nbg1-1/owncloud/config:/var/www/html/config
          - /mnt/volume-nbg1-1/owncloud/apps:/var/www/html/apps
          - /mnt/volume-nbg1-1/owncloud/sessions:/var/www/html/sessions
    
      mariadb:
        image: mariadb:10.5
        container_name: owncloud_mariadb
        restart: always
        environment:
          - MYSQL_ROOT_PASSWORD=passwd
          - MYSQL_USER=owncloud
          - MYSQL_PASSWORD=passwd
          - MYSQL_DATABASE=owncloud
        volumes:
          - /mnt/volume-nbg1-1/owncloud/mariadb:/var/lib/mysql
    
      redis:
        image: redis:6
        container_name: owncloud_redis
        restart: always
        volumes:
          - /mnt/volume-nbg1-1/owncloud/redis:/data
    
    volumes:
      owncloud-data:
    

    Note that I switched to a named volume here because I don't know the initial contents of that directory or directory owner/permissions it expects.