JeffProd
JeffProd

Reputation: 3148

Local docker volume with write permission from www-data

Here is part of my Dockerfile :

RUN mkdir /data
RUN chown www-data:www-data /data
RUN chmod 664 /data
VOLUME ["/data"]

I create the image with the command :

docker build -t webapp .

I run it like this :

docker run -d -p 80:80 -v /home/user/data:/data webapp

But in my host user dir, the data directory is created like this :

drwxr-xr-x  2 root root 4,0K avril 28 21:52 data

And in the image (docker exec -it CONTAINER_ID bash) i have :

drwxr-xr-x   2 root root 4096 Apr 28 19:52 data

So commands are ignored from the Dockerfile.
How can a web docker app simply get permission to write on a host directory ?

Upvotes: 0

Views: 1983

Answers (1)

jazgot
jazgot

Reputation: 2073

So you are building an image, setting chmods, and it's all cool. But then you run the container with -v option, which means /data will be replaced with mounted volume. At this time all files and permissions from built image are ignored. You can check this by running container without -v option. The solution is to create entrypoint script (with ENTRYPOINT or CMD command in Dockerfile) which will first fix permissions and then run original command for your image.

Upvotes: 1

Related Questions