<p>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.</p>

CC BY-SA 4.0
2023-08-18T13:00:10.470Z
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
CC BY-SA 4.0
2023-08-24T18:37:14.893Z
No, I don't have anything related to docker in /etc/apparmor and subdirectories.
witpok
CC BY-SA 4.0
2023-08-18T08:00:58.997Z
2023-08-18T08:00:58.997Z
witpok
<p>Maybe this, instead (have not tested this):</p>
<pre><code>FROM php:7.1.33-fpm AS base
RUN mkdir /home/www-data \
&amp;&amp; ls -ld /home/* \
&amp;&amp; usermod -d /home/www-data www-data \
&amp;&amp; ls -ld /home/* \
&amp;&amp; chown -R www-data /home/www-data \
&amp;&amp; ls -ld /home/* \
&amp;&amp; chmod -R 0777 /home/www-data \
&amp;&amp; ls -ld /home/*
</code></pre>

CC BY-SA 4.0
2023-08-18T08:25:08.280Z
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
CC BY-SA 4.0
2023-08-17T13:18:12.840Z
2023-08-17T13:18:12.840Z
mikequentel
<p>I can't change ownership of newly created directory inside of docker container. It is not a volume and <code>chown</code> 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: <code>Docker version 20.10.25, build 20.10.25-0ubuntu1~22.04.1</code></p>
<p>I have simplified my use case to this most basic Dockerfile (php version doesn't matter, tried with 8.0 as well):</p>
<pre><code>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/*
</code></pre>
<p>I run it with <code>docker build . --no-cache</code>, so there is no docker-compose used, anything cached etc.</p>
<p>My partial output:</p>
<pre><code>Step 5/9 : RUN ls -ld /home/*
 ---&gt; Running in faee10891512
drwxr-xr-x 2 root root 4096 Aug 17 08:46 /home/www-data
Removing intermediate container faee10891512
 ---&gt; bd417136c193
Step 6/9 : RUN chown -R www-data /home/www-data
 ---&gt; Running in 7656908de5e0
Removing intermediate container 7656908de5e0
 ---&gt; e25a42b7f73b
Step 7/9 : RUN ls -ld /home/*
 ---&gt; Running in e916fca31c51
drwxr-xr-x 1 root root 4096 Aug 17 08:46 /home/www-data
Removing intermediate container e916fca31c51
 ---&gt; be3154bf3ad6

</code></pre>
<p>Expected output (just taken from docker run on windows):</p>
<pre><code>#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
</code></pre>
<p>I am really puzzled about this, anyone has and idea what should I try next?</p>

<docker><linux>
Chown inside docker container is not changing directory owner
witpok
# Chown inside docker container is not changing directory owner

(Asked by: username_0 on 2023-08-17)

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?

**Tags:** docker, linux


---

## 2 answers

### Answer by username_0 on 2023-08-18. Score: 0 | Accepted answer

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.

> **Comments:**
> **username_1**: 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)  
> **username_0**: No, I don't have anything related to docker in /etc/apparmor and subdirectories.  

---

### Answer by username_2 on 2023-08-17. Score: 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/*

> **Comments:**
> **username_0**: 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.  

---

