title: Docker run command is not applied to the image
body: <p>I have a Dockerfile as follows:</p>
  
  <pre><code>FROM jenkins/jenkins:2.119
  
  USER jenkins
  ENV HOME /var/jenkins_home
  
  COPY --chown=jenkins:jenkins ssh ${HOME}/.ssh/
  
  RUN chmod 700 ${HOME}/.ssh &amp;&amp; \
      chmod 600 ${HOME}/.ssh/*
  </code></pre>
  
  <p>The ssh directory has 755/644 on the dir/file on the build machine. However, when I build with</p>
  
  <pre><code>docker build -t my/temp .
  </code></pre>
  
  <p>and start the image with an ls command</p>
  
  <pre><code>docker run -it --rm my/temp ls -la /var/jenkins_home/.ssh
  </code></pre>
  
  <p>neither of the chmod commands are applied to the image</p>
  
  <pre><code>drwxr-xr-x 2 jenkins jenkins 4096 May  3 12:46 .
  drwxr-xr-x 4 jenkins jenkins 4096 May  3 12:46 ..
  -rw-r--r-- 1 jenkins jenkins  391 May  3 11:42 known_hosts
  </code></pre>
  
  <p>During the build I see</p>
  
  <pre><code>Step 4/6 : COPY --chown=jenkins:jenkins ssh ${HOME}/.ssh/
   ---&gt; 58e0d8242fac
  Step 5/6 : RUN chmod 700 ${HOME}/.ssh &amp;&amp;     chmod 600 ${HOME}/.ssh/*
   ---&gt; Running in 0c805d4d4252
  Removing intermediate container 0c805d4d4252
   ---&gt; bbfc828ace79
  </code></pre>
  
  <p>It looks like the chmod is discarded. How can I stop this happening?</p>
  
  <p>I'm using latest Docker (Edge) on Mac OSX 
  Version 18.05.0-ce-rc1-mac63 (24246); edge 3b5a9a44cd</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>With --rm didn't work either (after deleting image and rebuilding) but didn't get remove message</p>
  
  <pre><code>docker build -t my/temp --rm=false .
  
  run -it --rm my/temp ls -la /var/jenkins_home/.ssh
  drwxr-xr-x 2 jenkins jenkins 4096 May  3 15:42 .
  drwxr-xr-x 4 jenkins jenkins 4096 May  3 15:42 ..
  -rw-r--r-- 1 jenkins jenkins  391 May  3 11:42 known_hosts
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>So basically a bug in Docker where a base image with a VOLUME causes chmod to fail and similarly RUN mkdir on the volume failed but COPY did, but left the directory with the wrong permissions. Thanks to <a href="https://stackoverflow.com/users/933963/bkconrad">bkconrad</a>.</p>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>Created fork with a fix here <a href="https://github.com/systematicmethods/jenkins-docker" rel="nofollow noreferrer">https://github.com/systematicmethods/jenkins-docker</a>
  build.sh will build an image locally</p>