Answers: <p>Try this, instead (have not tested this):</p>
  <pre><code>FROM debian
  
  RUN echo &quot;START&quot; \
  &amp;&amp; whoami \
  &amp;&amp; groupadd -g 1023 bolek \
  &amp;&amp; useradd -u 1023 -m -g bolek -s /bin/bash bolek \
  &amp;&amp; ls -ld /home/bolek \
  &amp;&amp; chown bolek:bolek /home/bolek \
  &amp;&amp; ls -ld /home/bolek
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2023-08-17T13:23:23.857Z
Answers: 2023-08-17T13:23:23.857Z
Answers: mikequentel
Body: <p>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 &quot;chown&quot; can't change it.</p>
  <p>What's wrong here? What should I do to make the homedir be owned by the user?</p>
  <p>This is my Dockerfile:</p>
  <pre><code>FROM debian
  
  RUN echo &quot;START&quot;
  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
  </code></pre>
  <p>And this is the result of running it:</p>
  <pre><code>$ docker build .
  Sending build context to Docker daemon  2.048kB
  Step 1/8 : FROM debian
   ---&gt; 278727474c29
  Step 2/8 : RUN echo &quot;START&quot;
   ---&gt; Running in ea2ef07f8cf7
  START
  Removing intermediate container ea2ef07f8cf7
   ---&gt; 380cf07ef790
  Step 3/8 : RUN whoami
   ---&gt; Running in 310b27eb1667
  root
  Removing intermediate container 310b27eb1667
   ---&gt; f2d3e944ba74
  Step 4/8 : RUN groupadd -g 1023 bolek
   ---&gt; Running in 7a6ed0dfa95f
  Removing intermediate container 7a6ed0dfa95f
   ---&gt; 00edbb567c42
  Step 5/8 : RUN useradd -u 1023 -m -g bolek -s /bin/bash bolek
   ---&gt; Running in 29df766891ca
  Removing intermediate container 29df766891ca
   ---&gt; a16b10eb3ed7
  Step 6/8 : RUN ls -ld /home/bolek
   ---&gt; Running in c13578f95134
  drwxr-xr-x 2 root root 4096 Aug 13 05:42 /home/bolek
  Removing intermediate container c13578f95134
   ---&gt; 69dbc583fd7a
  Step 7/8 : RUN chown bolek:bolek /home/bolek
   ---&gt; Running in a0cd64572d84
  Removing intermediate container a0cd64572d84
   ---&gt; c3d50f8cdf97
  Step 8/8 : RUN ls -ld /home/bolek
   ---&gt; Running in 1cd57cf5f75b
  drwxr-xr-x 1 root root 4096 Aug 13 05:42 /home/bolek
  Removing intermediate container 1cd57cf5f75b
   ---&gt; ceb5c78c2786
  Successfully built ceb5c78c2786
  </code></pre>
  <p>I noticed that the problem happens only on some computers - on other ones the very same Dockerfile behaves correctly.</p>
  <p>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.</p>
  
Tags: <docker>
Title: docker: homedir does not belong to the user
UserDisplayName: user983447
ThreadText: # docker: homedir does not belong to the user
  
  (Asked by: username_0 on 2023-08-13)
  
  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.
  
  **Tags:** docker
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-08-17. Score: 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
  
  ```
  
  
  ---
  
  