Docker File Ownership

I want to configure file permissions for files that I add to the docker sample. I have this simple docker file:

FROM ubuntu:utopic WORKDIR /app RUN groupadd -g 1000 baz && useradd -u 1000 -g baz baz -d /app -s /bin/false RUN chown baz:baz /app && chmod g+s /app # want this to be have group baz ADD foo /app/ 

Building this with docker build -t abc . where is the foo file in . creates an image. However, permissions on /app/foo inside are not what I want.

 docker run abc ls -la total 12 drwxr-xr-x 2 baz baz 4096 Sep 2 23:21 . drwxr-xr-x 37 root root 4096 Sep 3 07:27 .. -rw-rw-r-- 1 root root 419 Sep 2 21:43 foo 

Please note that the foo file does not belong to the baz group, despite the setgid bit specified in the /app directory. I could use the RUN chown -R baz:baz /app after adding the files, but this will copy the created layer (note the size of the two layers below):

 docker history abc | head -n 3 IMAGE CREATED CREATED BY SIZE COMMENT b95a3d798873 About a minute ago /bin/sh -c chown -R baz:baz /app 419 B 7e007196c116 About a minute ago /bin/sh -c #(nop) ADD file:2b91d9890a9c392390 419 B 

Is there any way around this and accessing the added files that I want?

+5
source share
1 answer

Instead of adding foo directly, you can pack it into a tarball and set permissions for a specific UID / GID. Here is a post on how to do this: https://unix.stackexchange.com/questions/61004/force-the-owner-and-group-for-the-contents-of-a-tar-file

After that, you can simply expand it in your Docker image ( ADD untars automatically). You should see permissions saved without an additional layer.

+4
source

All Articles