Docker Community Forums

Share and learn in the Docker community.

How do i change named volume host files location?

docker

#1

Hello there! Help me solve my problem out, please. Can’t solve it about a week.

What i have:
I have production server with web-application on it, running under docker. I use docker-compose and named volumes. Named volumes helps me share data between containers.
Also server has two disks: HDD (2 TB) and SSD (512 GB).

What i need:
I need to store one part of persistent data on HDD (large user files, for example), another part on SSD (source code and database).

What i do:
After read tons of docs and manuals i found the way that worked for another people (but not for me).
All paths to host directories (for example: “/awesomeapp_source_files”) was created manually. Also all need access rights was configured (owners and permissions).

My docker-compose.prod.yml file:

volumes:
   volume_source:
       driver: local
       driver_opts:
           type: none
           o: bind
           # SSD
           device: /awesomeapp_source_files
   volume_database:
       driver: local
       driver_opts:
           type: none
           o: bind
           # SSD
           device: /awesomeapp_database_files
   volume_public_data:
       driver: local
       driver_opts:
           type: none
           o: bind
           # HDD
           device: /var/awesomeapp/public_files
   volume_private_data:
       driver: local
       driver_opts:
           type: none
           o: bind
           # HDD
           device: /var/awesomeapp/private_files

services:
   app:
       volumes:
           - volume_source:/var/www
           - volume_public_data:/var/www/public/data:nocopy
           - volume_private_data:/var/www/data:nocopy

   nginx:
       volumes:
           - volume_source:/var/www:nocopy
           - volume_public_data:/var/www/public/data:nocopy
           - volume_private_data:/var/www/data:nocopy

   mysql:
       volumes:
           - volume_database:/var/lib/mysql

   php:
       volumes:
           - volume_source:/var/www:nocopy
           - volume_public_data:/var/www/public/data
           - volume_private_data:/var/www/data

The key is:

driver_opts:
    type: none
    o: bind
    device: /path/to/folder/on/host

If i comment this settings - named volumes stores under standard paths (“/var/lib/docker/volumes/{NAMED_VOLUME_NAME}/_data”). And my application works as expected!

But if i use this settings - my directories on hosts (“/awesomeapp_source_files”, “/var/awesomeapp/private_files”, “/var/awesomeapp/public_files”) and in docker containers (“/var/www”, “/var/www/data”, “/var/www/public/data”) becomes empty.
My suggestion is that data doesn’t shared from containers to host (initial copy), but empty data copied from host to container (with removing all files and directories in “/var/www”).
But i have no idea how to check and solve it.

Please, help me solve it out.

P.S. Sorry for my bad english.