I believe the correct way to do this is by mounting the external drive on your host system, and then mapping the volume onto the container at startup.
I'll provide a basic example with the NextCloud container.
So mount your external drive normally on your host system - let's say you mount it to /mnt/my-data
.
Next, you want to create a directory for the NextCloud data:
$ mkdir /mnt/my-data/nc-data
Then, when running your NextCloud container image, provide information to map the volume onto the internal NextCloud data directory:
$ docker run -d \
-v /mnt/my-data/nc-data:/var/www/html \
nextcloud
If you want an external database, do the same for MariaDB:
$ mkdir /mnt/my-data/nc-mariadb
$ docker run -d \
-v /mnt/my-data/nc-mariadb:/var/lib/mysql \
mariadb
Make sure the owner and permissions for the data directories match those of the container running.
I find that it's easiest to use docker-compose
to generate a complete installation file of the entire container stack. Using the above example, and the docker-compose
file shown on Docker Hub, this would be the result:
version: '2'
services:
db:
image: mariadb
restart: always
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- /mnt/my-data/nc-mariadb:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_PASSWORD=
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app:
image: nextcloud
restart: always
ports:
- 8080:80
links:
- db
volumes:
- /mnt/my-data/nc-data:/var/www/html
environment:
- MYSQL_PASSWORD=
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
Note that the "volumes" section is not present, since we map an absolute path on your host system (/mnt/my-data/nc-xxxx
) and not a named volume.