Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hasnat/docker-volumes-provisioner
Helper to provision your docker volumes with appropriate permissions chown and chmod
https://github.com/hasnat/docker-volumes-provisioner
docker docker-compose permissions provisioning volumes
Last synced: 7 days ago
JSON representation
Helper to provision your docker volumes with appropriate permissions chown and chmod
- Host: GitHub
- URL: https://github.com/hasnat/docker-volumes-provisioner
- Owner: hasnat
- Created: 2019-06-16T00:04:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-28T05:52:14.000Z (10 months ago)
- Last Synced: 2024-03-17T08:51:57.970Z (8 months ago)
- Topics: docker, docker-compose, permissions, provisioning, volumes
- Language: Dockerfile
- Homepage:
- Size: 10.7 KB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Docker Volumes Provisioner
hub.docker.com [hasnat/volumes-provisioner](https://hub.docker.com/r/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](https://linux.die.net/man/1/sed) and [install](https://linux.die.net/man/1/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](https://hub.docker.com/_/mysql) data folder needs to be 1000:1000
- [prometheus](https://hub.docker.com/r/prom/prometheus) needs 65534:65534
- [grafana](https://hub.docker.com/r/grafana/grafana) needs 472:472### Config
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`### draw
```
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"
```#### Local Run example
```
docker run --rm \
-e PROVISION_DIRECTORIES=1000:1000:0755:/var/www \
-v `pwd`/data:/var/www \
hasnat/volumes-provisioner
ls -dhn data
```#### Docker Compose prometheus example
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: noneprometheus:
image: prom/prometheus:v2.3.2
ports:
- "9090:9090"
depends_on:
- volumes-provisioner
volumes:
- "./var/data/prometheus/data:/prometheus/data"```
#### Build locally
```
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
```#### Notes
Won't work for docker for macos volume mounts