Change data directory with Docker

Dear all,

I’m new to nexcloud but I want to use it.

I installed nextcloud in a docker container, I can access to the interface. So this is ok.

But now I would like to have all data in a different drive.
For example. Hard Drive 2 with 2TB should be only have the files which are stored in nextcloud.

How can I achive this?
I tried to search it via Google but could not find a tutorial to achive it.

Can someone assist? What Information do you need?

I am running Docker on Windows Server 2016.

Thank you very much

I didn’t find any tutorial for this precise use case but I can give you some answer.

You’ll have to create a volume with local-persist driver.
You can see details here:

To install the local-persist driver:
curl -fsSL https://raw.githubusercontent.com/CWSpear/local-persist/master/scripts/install.sh | sudo bash

To create a persistent volume named “nextcloud-data”:
docker volume create -d local-persist -o mountpoint=/data/nextcloud-data --name=nextcloud-data

Then, you’ll have to map this volume to your Nextcloud docker when you create it.
You can do it with docker-compose like in this docker-compose.yml to adapt at your needs.

version: '3.5'

services:

  proxy:
    image: jwilder/nginx-proxy:alpine
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
    container_name: nextcloud-proxy
    networks:
            nextcloud:
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./proxy/conf.d:/etc/nginx/conf.d:rw
      - ./proxy/vhost.d:/etc/nginx/vhost.d:rw
      - ./proxy/html:/usr/share/nginx/html:rw
      - ./proxy/certs:/etc/nginx/certs:ro
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    restart: unless-stopped

  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: nextcloud-letsencrypt
    depends_on:
      - proxy
    networks:
            nextcloud:
    volumes:
      - ./proxy/certs:/etc/nginx/certs:rw
      - ./proxy/vhost.d:/etc/nginx/vhost.d:rw
      - ./proxy/html:/usr/share/nginx/html:rw
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    restart: unless-stopped

  db:
    image: mariadb
    container_name: nextcloud-mariadb
    networks:
            nextcloud:
    volumes:
      - db:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MYSQL_ROOT_PASSWORD=*********
      - MYSQL_PASSWORD=*********
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=ncuser
    restart: unless-stopped

  app:
    image: nextcloud:latest
    container_name: nextcloud-app
    networks:
            nextcloud:
    depends_on:
      - letsencrypt
      - proxy
      - db
    volumes:
      - nextcloud-data:/var/www/html
      - /etc/localtime:/etc/localtime:ro
    environment:
      - VIRTUAL_HOST=cloud.mydomain.tld
      - LETSENCRYPT_HOST=cloud.mydomain.tld
      - LETSENCRYPT_EMAIL=administrator@mydomain.tld
    restart: unless-stopped

volumes:
  nextcloud-data:
          external: true
  db:

networks:
  nextcloud:
          name: my-network

What’s important in this file is the mapping between path within the Docker and the volume name:

    volumes:
      - nextcloud-data:/var/www/html

This will tell docker-compose that the /var/www/html will be in your volume that you created and named “nextcloud-data”

volumes:
  nextcloud-data:
          external: true

And that will tell docker-compose that you’ve already created this volume and it’s name is “nextcloud-data” otherwise docker-compose will create a new volume named “nextcloud-data” and will prefix it with the stack name (here “nextcloud” so it would be “nextcloud_nextcloud-data”.

PS: of course since you’re running that on a Windows Server 2018, you’ll have to adapt the path.

1 Like