title: Docker volume change owner to non-root
body: <p>I want to create an <code>uploads</code> volume and set its owner to the <code>node</code> user. But upon running the container I find that the volume's owner is <code>root</code>. This is my Docker file:</p>
  <pre><code>FROM node:12.21
  RUN apt-get update &amp;&amp; apt-get -y install curl vim bash nano
  
  WORKDIR /home/node/app
  
  COPY package.json .
  COPY yarn.lock .
  
  RUN mkdir ./uploads
  
  RUN chown -R node:node .
  USER node
  
  RUN yarn install
  
  COPY --chown=node:node . .
  
  VOLUME /home/node/app/uploads
  </code></pre>
  <p>I use <code>docker-compose build</code> then <code>docker-compose up</code> to build and run; my <code>docker-compose.yml</code> also contains a volume instruction:</p>
  <pre><code>services:
    ...
    server:
      ...
      volumes:
        - ./uploads:/home/node/app/uploads
  </code></pre>
  <p>My tests show that this instruction in <code>docker-compose.yml</code> is what's causing the problem -- without it the <code>uploads</code> directory owner is correctly set to <code>node</code> -- but I don't understand why. Is the instruction in <code>docker-compose.yml</code> redundant in this case? How about if I wanted to map the volume to a local directory (for which I believe this instruction would be necessary)?</p>