Docker Image that Allows Write Access to the Docker Container User on a Persistent Volume
2.5K
Docker Image that Allows Write Access to the Docker Container User on a Persistent Volume, i.e. to be used in Docker Compose, Docker Swarm, Kubernets.
When you attach volumes to a Docker service, the files and directories are typically owned by root (user ID 0). This creates permission issues when your containerized application tries to write to these mounted volumes, as most containers run as a non-root user for security reasons.
This image solves this problem by:
/app to the container's non-root user (somebody by default)sleep infinityUse this as a sidecar container in your docker-compose setup to grant write access to shared volumes:
services:
allow-write-access:
image: mwaeckerlin/allow-write-access:latest
volumes:
- app-data:/app
your-app:
image: your-app-image
volumes:
- app-data:/app
depends_on:
- allow-write-access
volumes:
app-data:
The allow-write-access service will change the ownership of the /app directory in the shared volume, allowing your-app to write to it.
You can attach multiple volumes at or below /app:
services:
allow-write-access:
image: mwaeckerlin/allow-write-access:latest
volumes:
- vol1:/app/vol1
- vol2:/app/vol2
your-app:
image: your-app-image
volumes:
- vol1:/app/vol1
- vol2:/app/vol2
depends_on:
- allow-write-access
volumes:
vol1:
vol2:
This image is designed to be used in docker-compose, Docker Swarm, or Kubernetes where the container should not terminate (hence sleep infinity).
Build and push the image:
npm run build
This image is based on:
ALLOW_USERThe image uses a multi-stage build to extract only the necessary binaries:
/bin/chown, /bin/sh, /bin/sleep, /bin/busybox and the dynamic linker from mwaeckerlin/very-basemwaeckerlin/scratch containing only these executablesThe binaries /bin/chown, /bin/sh, and /bin/sleep are symbolic links to /bin/busybox, which is a multi-call binary that provides implementations of many Unix utilities in a single executable.
Content type
Image
Digest
sha256:738bbc7a4…
Size
297.3 kB
Last updated
1 day ago
docker pull mwaeckerlin/allow-write-access