0

I can't change ownership of newly created directory inside of docker container. It is not a volume and chown runs correctly for all my colleagues - the only difference is I'm running docker on linux while they are working on macs and windows (what should not matter, right?). My docker version: Docker version 20.10.25, build 20.10.25-0ubuntu1~22.04.1

I have simplified my use case to this most basic Dockerfile (php version doesn't matter, tried with 8.0 as well):

FROM php:7.1.33-fpm AS base
RUN mkdir /home/www-data
RUN ls -ld /home/*
RUN usermod -d /home/www-data www-data
RUN ls -ld /home/*
RUN chown -R www-data /home/www-data
RUN ls -ld /home/*
RUN chmod -R 0777 /home/www-data
RUN ls -ld /home/*

I run it with docker build . --no-cache, so there is no docker-compose used, anything cached etc.

My partial output:

Step 5/9 : RUN ls -ld /home/*
 ---> Running in faee10891512
drwxr-xr-x 2 root root 4096 Aug 17 08:46 /home/www-data
Removing intermediate container faee10891512
 ---> bd417136c193
Step 6/9 : RUN chown -R www-data /home/www-data
 ---> Running in 7656908de5e0
Removing intermediate container 7656908de5e0
 ---> e25a42b7f73b
Step 7/9 : RUN ls -ld /home/*
 ---> Running in e916fca31c51
drwxr-xr-x 1 root root 4096 Aug 17 08:46 /home/www-data
Removing intermediate container e916fca31c51
 ---> be3154bf3ad6

Expected output (just taken from docker run on windows):

#8 [5/9] RUN ls -ld /home/*
#8 sha256:ab73f23a9843a55ca731c83532c9f1b95e738525c2a8437f58ed7c17d0cf245e
#8 0.457 drwxr-xr-x 2 root root 4096 Aug 17 08:40 /home/www-data
#8 DONE 0.5s

#9 [6/9] RUN chown -R www-data /home/www-data
#9 sha256:686bd64c892edc235610feb148f1a9213bdf9238e62e74f1ca87da416c97eb99
#9 DONE 0.5s

#10 [7/9] RUN ls -ld /home/*
#10 sha256:e37fbdcf3bd0ae93dd19f8bc4b81d3c22fec176a3ef6d9b957c9c46787cb79a0
#10 0.434 drwxr-xr-x 1 www-data root 4096 Aug 17 08:40 /home/www-data
#10 DONE 0.4s

I am really puzzled about this, anyone has and idea what should I try next?

2 Answers 2

0

Maybe this, instead (have not tested this):

FROM php:7.1.33-fpm AS base
RUN mkdir /home/www-data \
&& ls -ld /home/* \
&& usermod -d /home/www-data www-data \
&& ls -ld /home/* \
&& chown -R www-data /home/www-data \
&& ls -ld /home/* \
&& chmod -R 0777 /home/www-data \
&& ls -ld /home/*
1
  • Unfortunately this hasn't changed the output, I have solved it with total reinstallation of docker. The root cause of the problem shall remain a mystery.
    – witpok
    Aug 18 at 8:25
0

I have solved this problem by removing docker completely and installing it as Docker Desktop from .deb package provided from . After that, chown started to work as it should.

2
  • This may have been an apparmor issue to begin with, can you check the contents of /etc and see if their are any scripts relevant to docker in your apparmor configs? (I've had similar issues with selinux on Redhat derivatives)
    – Peter Turner
    Aug 18 at 13:00
  • No, I don't have anything related to docker in /etc/apparmor and subdirectories.
    – witpok
    Aug 24 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.