hub.docker.com hasnat/volumes-provisioner
An alpine based helper image to essentially make directory with appropriate owner and permissions to be used by other containers. This is achieved by sed and install.
Most images require data folders to be under certain permissions, for mounted volumes directories have to be created and modified before container start. e.g.
- mysql data folder needs to be 1000:1000
- prometheus needs 65534:65534
- grafana needs 472:472
Pass config as env var PROVISION_DIRECTORIES
uid:gid:mode:dir(s) e.g. 1000:1000:0755:/var/www
Can contain multiple directories separated by space and/or multiple configs separated by ;
e.g.
1000:1000:0755:/var/www/html
1000:1000:0755:/var/www /var/www/html
1000:1000:0755:/var/www /var/www/html;1001:1001:0755:/var/app /var/app/cache
PROVISION_DIRECTORIES
sed -d, --directory
treat all arguments as
directory names; create all
components of the specified
([0-9]+):([0-9]+):([0-9]+):([^:;]+);? directories
│ │ │ │ │
│ │ │ │ │ -o, --owner=OWNER
│ │ │ │ │ set ownership (super-user only)
└─────┐ └───┐ └─┐ ┌────┘ └────┐
│ │ │ │ │ -g, --group=GROUP
│ │ │ │ │ set group ownership, instead of
│ │ │ │ │ process' current group
▼ ▼ ▼ ▼ ▼
install -d -o \1 -g \2 -m \3 \4 ; ls -dhn \4 ; -m, --mode=MODE
set permission mode (as in
chmod), instead of rwxr-xr-x
Examples
PROVISION_DIRECTORIES: "1000:1000:0755:/var/www/html"
PROVISION_DIRECTORIES: "1000:1000:0755:/var/www /var/www/html"
PROVISION_DIRECTORIES: "1000:1000:0755:/var/www /var/www/html;1000:1000:0755:/var/app /var/app/cache"
PROVISION_DIRECTORIES: "65534:65534:0755:/var/data/prometheus/data"
docker run --rm \
-e PROVISION_DIRECTORIES=1000:1000:0755:/var/www \
-v `pwd`/data:/var/www \
hasnat/volumes-provisioner
ls -dhn data
Here using depends_on we make sure directory with correct permissions is created before prometheus starts
version: '2'
services:
volumes-provisioner:
image: hasnat/volumes-provisioner
environment:
PROVISION_DIRECTORIES: "65534:65534:0755:/var/data/prometheus/data"
volumes:
- "./var/data:/var/data"
network_mode: none
prometheus:
image: prom/prometheus:v2.3.2
ports:
- "9090:9090"
depends_on:
- volumes-provisioner
volumes:
- "./var/data/prometheus/data:/prometheus/data"
docker build -t volumes-provisioner .
docker run --rm \
-e PROVISION_DIRECTORIES=1000:1000:0755:/var/www \
-v `pwd`/data:/var/www \
volumes-provisioner
ls -dhn data
Won't work for docker for macos volume mounts