Answer the question
In order to leave comments, you need to log in
How to change storage path of named volumes on host machine in docker?
What is available:
There is a production server on which it is planned to keep a web application that will be spinning using docker. I use docker-compose and named volumes to help share data between containers.
The server has 2 disks: HDD (2 TB) and SSD (500 GB).
What you need:
You need to store part of the persistent data on the HDD (for example, large user data), and store the rest of the data on the SSD (source code and database).
What I have already tried:
After reading hundreds of manuals and articles in the documentation, I found the following approach, described below (docker-compose code is attached).
This approach, judging by the information found, works for most people (but not for me, for some reason).
It is also worth noting that all necessary paths on the host machine (for example: “/awesomeapp_source_files” ) have been pre-created and all permissions and owners have been configured.
docker-compose.prod.yml
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:
# Контейнер содержит исходный код приложения. Исходники расшариваются при помощи named volumes.
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
driver_opts:
type: none
o: bind
device: /path/to/folder/on/host
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question