title: How to create and add user with password in alpine Dockerfile?
body: <p>The following <code>Dockerfile</code> works fine for Ubuntu:</p>
  <pre><code>FROM ubuntu:20.04
  SHELL [&quot;/bin/bash&quot;, &quot;-c&quot;]
  ARG user=hakond
  ARG home=/home/$user
  RUN useradd --create-home -s /bin/bash $user \
          &amp;&amp; echo $user:ubuntu | chpasswd \
          &amp;&amp; adduser $user sudo
  
  WORKDIR $home
  USER $user
  COPY --chown=$user entrypoint.sh .
  RUN chmod +x entrypoint.sh
  ENTRYPOINT [&quot;./entrypoint.sh&quot;]
  </code></pre>
  <p>where <code>entrypoint.sh</code> is</p>
  <pre><code>#! /bin/bash
  exec bash
  </code></pre>
  <p>How can I do the same in Alpine? I tried:</p>
  <pre><code>FROM alpine:3.12
  SHELL [&quot;/bin/sh&quot;, &quot;-c&quot;]
  RUN apk add --no-cache bash
  ARG user=hakond
  ARG home=/home/$user
  RUN addgroup -S docker
  RUN adduser \
      --disabled-password \
      --gecos &quot;&quot; \
      --home $home \
      --ingroup docker \
      $user
  WORKDIR $home
  USER $user
  COPY chown=$user entrypoint.sh .
  RUN chmod +x entrypoint.sh
  ENTRYPOINT [&quot;./entrypoint.sh&quot;]
  </code></pre>
  <p>But this fails to build:</p>
  <pre><code>$ docker build -t alpine-user .
  Sending build context to Docker daemon   5.12kB
  Step 1/12 : FROM alpine:3.12
   ---&gt; a24bb4013296
  Step 2/12 : SHELL [&quot;/bin/sh&quot;, &quot;-c&quot;]
   ---&gt; Using cache
   ---&gt; ce9a303c96c8
  Step 3/12 : RUN apk add --no-cache bash
   ---&gt; Running in e451a2481846
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
  (1/4) Installing ncurses-terminfo-base (6.2_p20200523-r0)
  (2/4) Installing ncurses-libs (6.2_p20200523-r0)
  (3/4) Installing readline (8.0.4-r0)
  (4/4) Installing bash (5.0.17-r0)
  Executing bash-5.0.17-r0.post-install
  Executing busybox-1.31.1-r16.trigger
  OK: 8 MiB in 18 packages
  Removing intermediate container e451a2481846
   ---&gt; 7b5f7f87bdf6
  Step 4/12 : ARG user=hakond
   ---&gt; Running in 846b4b12856e
  Removing intermediate container 846b4b12856e
   ---&gt; a0453cb6706e
  Step 5/12 : ARG home=/home/$user
   ---&gt; Running in 06550ad3f550
  Removing intermediate container 06550ad3f550
   ---&gt; 994d71fb0281
  Step 6/12 : RUN addgroup -S docker
   ---&gt; Running in 70aaec6f40e0
  Removing intermediate container 70aaec6f40e0
   ---&gt; 5188ed7b234c
  Step 7/12 : RUN adduser     --disabled-password     --gecos &quot;&quot;     --home $home     --ingroup docker     $user
   ---&gt; Running in ff36a7f7e99b
  Removing intermediate container ff36a7f7e99b
   ---&gt; 97f481916feb
  Step 8/12 : WORKDIR $home
   ---&gt; Running in 8d7f0411d6e3
  Removing intermediate container 8d7f0411d6e3
   ---&gt; 5de66f4b5d4e
  Step 9/12 : USER $user
   ---&gt; Running in ac4abac7c3a8
  Removing intermediate container ac4abac7c3a8
   ---&gt; dffd2185df1f
  Step 10/12 : COPY chown=$user entrypoint.sh .
  COPY failed: stat /var/snap/docker/common/var-lib-docker/tmp/docker-builder615220199/chown=hakond: no such file or directory
  </code></pre>