title: Docker container fails to write to a (non root) folder
body: <p>I run a docker container in order to extract files from a source folder into a destination folder. The source folder resides in my user's home directory so there is no problem to read from it or write. The destination folder on the other hand, is accessed only by a <em>nonrootuser</em>.</p>
  <p>When I ran the docker container with the <em>nonrootuser</em>, I cannot write in the container's folders (permission denied).
  On the other hand when I ran the container with my <em>user</em>, I cannot write to the destination folder.</p>
  <h3>Setup</h3>
  <p>I build the image like this</p>
  <p><code> docker build -t lftp .</code></p>
  <p>based on the following Dockerfile:</p>
  <p><strong>Dockerfile</strong></p>
  <pre><code>FROM debian:10
  RUN apt-get update &amp;&amp; apt-get  -y upgrade
  RUN apt-get -y install lftp dos2unix man
  # Adding the scripts
  COPY scripts /scripts
  WORKDIR /work
  # Adding the nonrootuser and his uid (`id -u nonrootuser`)
  RUN useradd -u 47001 nonrootuser &amp;&amp; mkhomedir_helper nonrootuser
  </code></pre>
  <p>Then I ran the container while binding the following volumes :</p>
  <ul>
  <li>download_folder</li>
  <li>destination_folder &lt;-&gt; this folder need to be accessed by a <em>nonrootuser</em></li>
  </ul>
  <pre><code>docker run -ti --rm --name=lftp_untar -u `id -u nonrootuser`:`id -g nonrootuser` -v ${download_folder}:/source -v ${destination_folder}:/target lftp bash /scripts/execute_untar.sh /source /target
  </code></pre>
  <p>Where:</p>
  <p><strong>execute_untar.sh</strong></p>
  <pre><code>#!/bin/bash
  
  source=$1
  target=$2
  
  if [ ! -d $source ]; then
    echo Can\'t access $source
    exit 1
  fi
  
  if [ ! -d $target ]; then
    echo Can\'t access $target
    exit 1
  fi
  
  if [ ! -w $target ]; then
    echo Can\'t write to $target
    exit 1
  fi
  
  # Then Read files from /scripts and /work folder 
  exclude_file=$(readlink -f /scripts/exclude.txt)
  log_file=$(readlink -f untar.log)
  
  
  </code></pre>