When defining named volumes in docker-compose.yml
, their names are prepended with their parent folder name. This causes a problem when scripts outside of docker compose have to interact with them. The question is, what is the best way to deal with this?
An example scenario would include the following docker-compose.yml
:
version: "3"
services:
nginx:
build: ./nginx
container_name: nginx
ports:
- "80:80"
volumes:
- jekyll-data:/usr/share/nginx/html:ro
networks:
backend:
volumes:
jekyll-data:
Where the jekyll-data
named volume is populated by the following bash script:
docker run \
--name helper \
--volume="parent_folder_jekyll-data:/web" \
-it busybox \
true
docker cp jekyll/web/. helper:/web
docker rm helper
In the above case, parent_folder
is the name of the parent folder. This means that moving the contents to a different folder would break the application. Is there a proper way to deal with this situation?
The abridged output of docker volume ls
where unnamed volumes have been removed:
DRIVER VOLUME NAME
local flaskthymedata_grafana-data
local flaskthymedata_influxdb-data
local flaskthymedata_postgres-data
local veleda_grafana-data
local veleda_influxdb-data
local veleda_jekyll-cache
local veleda_jekyll-data
local veleda_postgres-data
local veledaio_grafana-data
local veledaio_influxdb-data
local veledaio_jekyll-cache
local veledaio_jekyll-data
local veledaio_postgres-data
Where the jekyll-data named volume is populated by the following bash script
Why do you use a bash script to create a docker volume?