Dockerfile replicate the host user UID and GID to the image : <p>Similar to the <a href="https://stackoverflow.com/q/32397496/362754">SO post about replicating UID/GID in container from host</a> but how do you build the image with a user with replicate UID and GID? Preferably, how do you do it with a dockerfile? </p>

<p>I can do it with a bash script: </p>

<pre><code>#!/bin/bash

# current uid and gid
curr_uid=`id -u`
curr_gid=`id -g`

# create bb.dockerfile:
cat &lt;&lt; EOF1 &gt; bb.dockerfile
 FROM ubuntu:xenial-20170214
 ARG UNAME=testuser
EOF1

 echo ARG UID=${curr_uid} &gt;&gt; bb.dockerfile
 echo ARG GID=${curr_gid} &gt;&gt; bb.dockerfile

cat &lt;&lt; EOF2 &gt;&gt; bb.dockerfile
 RUN groupadd -g \$GID \$UNAME
 RUN useradd -m -u \$UID -g \$GID -s /bin/bash \$UNAME
 USER \$UNAME
 CMD /bin/bash
EOF2

docker build -f bb.dockerfile -t testimg .
</code></pre>

<p>This bash will generate a docker file as the following and build on it. </p>

<pre><code> FROM ubuntu:xenial-20170214
 ARG UNAME=testuser
 ARG UID=1982
 ARG GID=1982
 RUN groupadd -g $GID $UNAME
 RUN useradd -m -u $UID -g $GID -s /bin/bash $UNAME
 USER $UNAME
 CMD /bin/bash
</code></pre>

<p>What I'm asking for, is to remove the hardcoded host UID 1982 and GID 1982 from the dockerfile. </p>
