title: Docker user namespacing map user in container to host
body: <p>I'd like to map user postgres or root inside container to user myuser on the host. There's a lot of references to this online, but it is not very clear to me how to achieve the following:</p>
  
  <p>Is there a simple way to map arbitrary user inside container to user in host by a simple command line flag at the docker-run level</p>
  
  <p><strong>Map root user inside container to myuser on host</strong></p>
  
  <pre><code>docker run --user-remap "mysuser:root" -p 6379:6379 redis:alpine
  </code></pre>
  
  <p>and </p>
  
  <p><strong>Map postgres inside container to myuser on host</strong></p>
  
  <pre><code>docker run -it -p 5431:5432 --user-remap "myuser:postgres" --rm -v /home/myuser/data:/var/lib/postgresql/data postgres:9.6.0
  </code></pre>
  
  <p>I do not want to apply the same settings to all my containers. So doing this at the docker daemon level by applying</p>
  
  <pre><code>sudo docker daemon --userns-remap myuser
  </code></pre>
  
  <p>and updating /etc/passwd, /etc/group, /etc/subuid, /etc/subgid would not help solve my problem. Is there a way to solve this problem at the <code>docker run</code> stage, so that these settings can be applied on a container by container basis.</p>
  
  <p>Thanks</p>