I've noticed a new strange thing where file permissions reset while building a docker image.
Consider the following Dockerfile
:
FROM ubuntuRUN mkdir -p /home/user && \ useradd -l -u 1000 userRUN echo startRUN chown -R user:user /home/user && \ ls -lart /homeRUN echo look again && \ ls -lart /home
Using
$ docker --versionDocker version 20.10.25, build 20.10.25-0ubuntu1~22.04.1
As you can see, I chown
all /home/user
to be user:user
on the 3'rd RUN
. and it did work, as can be seen in the output of ls
.
But when looking again in the 4'th RUN
, I see these ownership got reset back to root
.
This is new to me. I don't know when/why it started happening.
Please help.
Here's the output of the build:
$ docker build . -t delmeSending build context to Docker daemon 2.048kBStep 1/5 : FROM ubuntu ---> a8780b506fa4Step 2/5 : RUN mkdir -p /home/user && useradd -l -u 1000 user ---> Running in 3c5322e6da14Removing intermediate container 3c5322e6da14 ---> b8cd6cff6cf1Step 3/5 : RUN echo start ---> Running in 84b28e26fe62startRemoving intermediate container 84b28e26fe62 ---> 0132b4cea87fStep 4/5 : RUN chown -R user:user /home/user && ls -lart /home ---> Running in 026d38b02676total 16drwxr-xr-x 1 user user 4096 Aug 21 22:31 userdrwxr-xr-x 1 root root 4096 Aug 21 22:31 .drwxr-xr-x 1 root root 4096 Aug 21 22:31 ..Removing intermediate container 026d38b02676 ---> ab43ecd201c5Step 5/5 : RUN echo look again && ls -lart /home ---> Running in 20a2618e9df5look againtotal 12drwxr-xr-x 1 root root 4096 Aug 21 22:31 userdrwxr-xr-x 1 root root 4096 Aug 21 22:31 .drwxr-xr-x 1 root root 4096 Aug 21 22:31 ..Removing intermediate container 20a2618e9df5 ---> 69affbc1656bSuccessfully built 69affbc1656bSuccessfully tagged delme:latest
--- UPDATE ---
I've downgraded to older docker.io
package:
sudo apt install docker.io=20.10.21-0ubuntu1~22.04.3
Now it works. I think something is wrong with the new version. Please ignore the fact that it pulls the ubuntu package.
$ docker build . -t delmeSending build context to Docker daemon 2.048kBStep 1/5 : FROM ubuntulatest: Pulling from library/ubuntub237fe92c417: Pull complete Digest: sha256:ec050c32e4a6085b423d36ecd025c0d3ff00c38ab93a3d71a460ff1c44fa6d77Status: Downloaded newer image for ubuntu:latest ---> 01f29b872827Step 2/5 : RUN mkdir -p /home/user && useradd -l -u 1000 user ---> Running in b40942bbcec8Removing intermediate container b40942bbcec8 ---> 0070af6f64e4Step 3/5 : RUN echo start ---> Running in 8c60a7f12b60startRemoving intermediate container 8c60a7f12b60 ---> 483f5c6a1e4cStep 4/5 : RUN chown -R user:user /home/user && ls -lart /home ---> Running in 7c529b3450d3total 16drwxr-xr-x 1 user user 4096 Aug 22 07:30 userdrwxr-xr-x 1 root root 4096 Aug 22 07:30 .drwxr-xr-x 1 root root 4096 Aug 22 07:30 ..Removing intermediate container 7c529b3450d3 ---> 3763ff4101a1Step 5/5 : RUN echo look again && ls -lart /home ---> Running in 9c12c1d3143flook againtotal 12drwxr-xr-x 1 user user 4096 Aug 22 07:30 userdrwxr-xr-x 1 root root 4096 Aug 22 07:30 .drwxr-xr-x 1 root root 4096 Aug 22 07:30 ..Removing intermediate container 9c12c1d3143f ---> f9c1f61b0596Successfully built f9c1f61b0596Successfully tagged delme:latest