Docker: Are volume locations changable?

Created on 27 Jan 2018  路  3Comments  路  Source: nextcloud/docker

I'd like to have the Nextcloud instance to be fully contained on a data raid if possible, to make the OS a non-concern e.g. be able to replace the base system, install docker, run compose from raid and pick up where left off.

I'm guessing the default volume locations are there for consistency's sake, as well as security, but would there be any issue with db:, nextcloud:, certs:, conf.d:, vhost.d:, html: being bound to an arbitrary location? I guess I'm wondering whether there are any files added or controlled by the base system that are needed by the containers, or if mounting for example /var/lib/mysql is best practice but would have the same result as /mnt/raid/nextcloud/mysql (assuming permissions mesh)?

help wanted question

Most helpful comment

By design docker volumes cannot contain any data before a container is run. So any proper docker image will not rely on data that's in the volume. Instead there are startup scripts in place to copy needed data or create a folder structure. (That's what the entrypoint.sh or docker-entrypoint.sh is for).

Here with the nextcloud container, the script checks if /var/www/html/version.php is present and if not it starts the installing routine.

All 3 comments

Inside the container I wouldn't recommend to change the locations.

However it is pretty easy to change the storage location on your host. Instead of using names volumes (docker stores them in /var/lib/docker/volumes) you could directly specify the path of your storage device.

Refer to docker-compose documentation.

Okay, so short syntax relative path sounds sensible:
- ./maria:/var/lib/mysql instead of db:/var/lib/mysql
- ./nextcloud:/var/www/html instead of nextcloud:/var/www/html
etc.

However, one thing I'd still like to verify is that these volumes are all arbitrary and do not rely on data existing on host for function? So when the db container lists a volume to mount as /var/lib/mysql, it's only writing and accessing it's own things, and it's not looking for anything external to what it's writing and nothing on the main machine needs the information written by the container.

I just want to make sure providing an arbitrary location for the volumes for Nextcloud wouldn't cause any breakage.

By design docker volumes cannot contain any data before a container is run. So any proper docker image will not rely on data that's in the volume. Instead there are startup scripts in place to copy needed data or create a folder structure. (That's what the entrypoint.sh or docker-entrypoint.sh is for).

Here with the nextcloud container, the script checks if /var/www/html/version.php is present and if not it starts the installing routine.

Was this page helpful?
0 / 5 - 0 ratings