title: Docker mount volumes as root
body: <p>Why does Docker mount volume as <code>root</code>, not as user which has run command <code>docker run</code>? Can this be changed by setting some parameters/arguments, etc.?</p>
  
  <p>MWE:</p>
  
  <pre><code>$ ls -la
  drwxr-xr-x 2 ubuntu   ubuntu   4096 Aug 22 18:09 shinylog
  
  $ docker run -v $(pwd)/test_dir/:/home/ --name nginx -d nginx
  bf340face11485a81ee7c208d490f11abbdc84089ffe9c01d71ffcf8b9ffc27d
  
  $ ls -la
  drwxr-xr-x 2 ubuntu   ubuntu   4096 Aug 22 18:09 shinylog
  drwxr-xr-x 2 root     root   4096 Aug 22 18:33 test_dir
  
  $ echo $USER
  ubuntu
  </code></pre>
  
  <p>EDIT:
  After installing docker I encountered error:</p>
  
  <pre><code>Got permission denied while trying to connect to the Docker 
  daemon socket at unix:///var/run/docker.sock: Get 
  http://%2Fvar%2Frun%2Fdocker.sock/v1.38/containers/json: dial 
  unix /var/run/docker.sock: connect: permission denied
  </code></pre>
  
  <p>and performed:</p>
  
  <pre><code>sudo usermod -a -G docker $USER
  </code></pre>
  
  <p>Maybe that's the problem?</p>