title: Set docker image username at container creation time?
body: <p>I have an OpenSuse 42.3 docker image that I've configured to run a code. The image has a single user(other than root) called "myuser" that I create during the initial Image generation via the Dockerfile. I have three script files that generate a container from the image based on what operating system a user is on. </p>
  
  <p><strong>Question</strong>: Can the username "myuser" in the container be set to the username of the user that executes the container generation script?</p>
  
  <p>My goal is to let a user pop into the container interactively and be able to run the code from within the container. The code is just a single binary that executes and has some IO, so I want the user's directory to be accessible from within the container so that they can navigate to a folder on their machine and run the code to generate output in their filesystem.</p>
  
  <p>Below is what I have constructed so far. I tried setting the USER environment variable during the linux script's call to <code>docker run</code>, but that didn't change the user from "myuser" to say "bob" (the username on the host machine that started the container). The mounting of the directories seems to work fine. I'm not sure if it is even possible to achieve my goal.</p>
  
  <p>Linux Container script:</p>
  
  <pre><code>username="$USER"
  userID="$(id -u)"
  groupID="$(id -g)"
  home="${1:-$HOME}"
  
  imageName="myImage:ImageTag"
  containerName="version1Image"
  
  docker run  -it -d --name ${containerName}  -u $userID:$groupID     \
              -e USER=${username} --workdir="/home/myuser"            \
              --volume="${home}:/home/myuser" ${imageName} /bin/bash  \
  </code></pre>
  
  <p>Mac Container script:</p>
  
  <pre><code>username="$USER"
  userID="$(id -u)"
  groupID="$(id -g)"
  home="${1:-$HOME}"
  
  imageName="myImage:ImageTag"
  containerName="version1Image"
  
  docker run  -it -d --name ${containerName}                          \
              --workdir="/home/myuser"            \
              --v="${home}:/home/myuser" ${imageName} /bin/bash  \
  </code></pre>
  
  <p>Windows Container script:</p>
  
  <pre><code>ECHO OFF
  SET imageName="myImage:ImageTag"
  SET containerName="version1Image"
  
  docker run -it -d --name %containerName% --workdir="/home/myuser" -v="%USERPROFILE%:/home/myuser" %imageName% /bin/bash
  
  
  echo "Container %containerName% was created."
  echo "Run the ./startWindowsLociStream script to launch container"
  </code></pre>