I ran into an instance where I needed to use a Docker volume with an absolute path outside of the system the system defined path used when containers are launched…here is a solution I found….
With the local
volume driver comes the ability to use arbitrary mounts; by using a bind mount you can achieve exactly this.
For setting up a named volume that gets mounted into /mnt/docker/volumes/mysql-database
, your docker-compose.yml would look like this:
volumes:
database:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/mnt/docker/volumes/mysql-database'
By using a bind mount you lose in flexibility since it’s harder to reuse the same volume. But you don’t lose anything in regards of functionality
Leave a Reply