title: Nextcloud with Docker: Can't create or write into the data directory
body: <p>I successfully installed Nextcloud 13.0 using Docker and Docker Compose.</p>
  
  <p>Here's the GitHub repo of the Docker image of Nextcloud:
  <a href="https://github.com/nextcloud/docker" rel="nofollow noreferrer">https://github.com/nextcloud/docker</a></p>
  
  <p>By default, my Nextcloud installation stores data to the following path:</p>
  
  <pre><code>/var/lib/docker/volumes/nextcloud_nextcloud/_data/data/user/files
  </code></pre>
  
  <p>My <code>/var</code> folder is located on a small partition while <code>/home</code> folder has about 2Tb of storage space. I'm trying to setup Nextcloud to store uploaded files to <code>/home/iamdocker/nextcloud/data</code> on the host machine but it doesn't work.</p>
  
  <p>The Nextcloud configuration page displays the following message :</p>
  
  <blockquote>
    <p><strong>Error</strong></p>
    
    <p>Can't create or write into the data directory
    /home/iamdocker/nextcloud/data/</p>
  </blockquote>
  
  <p>My Nextcloud installation (running in a Docker container) doesn't have the permission to write.</p>
  
  <p><strong>.env</strong></p>
  
  <pre><code>MYSQL_ROOT_PASSWORD=***********************
  MYSQL_DATABASE=nextcloud
  MYSQL_USER=nextcloud
  MYSQL_PASSWORD=************************************
  MYSQL_HOST=db
  
  NEXTCLOUD_VERSION=13.0
  NEXTCLOUD_ADMIN_USER=example
  NEXTCLOUD_ADMIN_PASSWORD=********************************
  NEXTCLOUD_TABLE_PREFIX=nc_
  NEXTCLOUD_DATA_DIR=/home/iamdocker/nextcloud/data/
  </code></pre>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>version: '2'
  
  volumes:
    nextcloud:
    db:
  
  services:
    db:
      image: mariadb
      env_file:
        - .env
      restart: always
      volumes:
        - db:/var/lib/mysql
      environment:
        - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
        - MYSQL_DATABASE=${MYSQL_DATABASE}
        - MYSQL_USER=${MYSQL_USER}
        - MYSQL_PASSWORD=${MYSQL_PASSWORD}
  
    app:
      image: nextcloud:${NEXTCLOUD_VERSION}
      env_file:
        - .env
      ports:
        - 8081:80
      links:
        - db
      volumes:
        - nextcloud:/var/www/html
        - ./data:/var/www/html/data
      environment:
        - NEXTCLOUD_ADMIN_USER=${NEXTCLOUD_ADMIN_USER}
        - NEXTCLOUD_ADMIN_PASSWORD=${NEXTCLOUD_ADMIN_PASSWORD}
        - NEXTCLOUD_TABLE_PREFIX=${NEXTCLOUD_TABLE_PREFIX}
        - NEXTCLOUD_DATA_DIR=${NEXTCLOUD_DATA_DIR}
      restart: always
  </code></pre>
  
  <p>Thank you.</p>