0

I created a Dockerfile which creates a new user. When I run this Dockerfile I see that the user is created, his homedir is created as well, but the homedir is owned by root - and even "chown" can't change it.

What's wrong here? What should I do to make the homedir be owned by the user?

This is my Dockerfile:

FROM debian

RUN echo "START"
RUN whoami
RUN groupadd -g 1023 bolek
RUN useradd -u 1023 -m -g bolek -s /bin/bash bolek
RUN ls -ld /home/bolek
RUN chown bolek:bolek /home/bolek
RUN ls -ld /home/bolek

And this is the result of running it:

$ docker build .
Sending build context to Docker daemon  2.048kB
Step 1/8 : FROM debian
 ---> 278727474c29
Step 2/8 : RUN echo "START"
 ---> Running in ea2ef07f8cf7
START
Removing intermediate container ea2ef07f8cf7
 ---> 380cf07ef790
Step 3/8 : RUN whoami
 ---> Running in 310b27eb1667
root
Removing intermediate container 310b27eb1667
 ---> f2d3e944ba74
Step 4/8 : RUN groupadd -g 1023 bolek
 ---> Running in 7a6ed0dfa95f
Removing intermediate container 7a6ed0dfa95f
 ---> 00edbb567c42
Step 5/8 : RUN useradd -u 1023 -m -g bolek -s /bin/bash bolek
 ---> Running in 29df766891ca
Removing intermediate container 29df766891ca
 ---> a16b10eb3ed7
Step 6/8 : RUN ls -ld /home/bolek
 ---> Running in c13578f95134
drwxr-xr-x 2 root root 4096 Aug 13 05:42 /home/bolek
Removing intermediate container c13578f95134
 ---> 69dbc583fd7a
Step 7/8 : RUN chown bolek:bolek /home/bolek
 ---> Running in a0cd64572d84
Removing intermediate container a0cd64572d84
 ---> c3d50f8cdf97
Step 8/8 : RUN ls -ld /home/bolek
 ---> Running in 1cd57cf5f75b
drwxr-xr-x 1 root root 4096 Aug 13 05:42 /home/bolek
Removing intermediate container 1cd57cf5f75b
 ---> ceb5c78c2786
Successfully built ceb5c78c2786

I noticed that the problem happens only on some computers - on other ones the very same Dockerfile behaves correctly.

I could reproduce the problem on Linux Mint 20.3, where docker version is 20.10.25 (build 20.10.25-0ubuntu1~20.04.1) and docker's server version is also 20.10.25.

1 Answer 1

0

Try this, instead (have not tested this):

FROM debian

RUN echo "START" \
&& whoami \
&& groupadd -g 1023 bolek \
&& useradd -u 1023 -m -g bolek -s /bin/bash bolek \
&& ls -ld /home/bolek \
&& chown bolek:bolek /home/bolek \
&& ls -ld /home/bolek

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.