title: Copying files with execute permissions in Docker Image
body: <p>Seems like a basic issue but couldnt find any answers so far .. </p>
  
  <p>When using ADD / COPY in Dockerfile and running the image on linux, the default file permission of the file copied in the image is 644.  The onwner of this file seems to be as 'root' </p>
  
  <p>However, when running the image, a non-root user starts the container and any file thus copied with 644 permission cannot execute this copied/added file and if the file is executed at ENTRYPOINT it fails to start with permission denied error. </p>
  
  <p>I read in one of the posts that COPY/ADD after Docker 1.17.0+ allows chown but in my case i dont know who will be the non-root user starting so i cannot set the permission as that user. </p>
  
  <p>I also saw another work around to ADD/COPY files to a different location and use RUN to copy them from the temp location to actual folder like what am doing below. But this approach doesnt work as the final image doesnt have the files in /otp/scm</p>
  
  <pre><code>#Installing Bitbucket and setting variables  
  WORKDIR /tmp
  ADD atlassian-bitbucket-${BITBUCKET_VERSION}.tar.gz .
  COPY bbconfigupdater.sh .
  
  #Copying Entrypoint script which will get executed when container starts 
  WORKDIR /tmp 
  COPY entrypoint.sh .
  
  RUN ls -lrth /tmp
  
  WORKDIR /opt/scm 
  RUN pwd &amp;&amp; cp /tmp/bbconfigupdater.sh /opt/scm \
   &amp;&amp; cp /tmp/entrypoint.sh /opt/scm \
   &amp;&amp; cp -r /tmp/atlassian-bitbucket-${BITBUCKET_VERSION} /opt/scm \
   &amp;&amp; chgrp -R 0 /opt/ \
   &amp;&amp; chmod -R 755 /opt/ \
   &amp;&amp; chgrp -R 0 /scm/bitbucket \
   &amp;&amp; chmod -R 755 /scm/bitbucket \
   &amp;&amp; ls -lrth /opt/scm &amp;&amp; ls -lrth /scmdata 
  </code></pre>
  
  <p>Any help is appreciated to figure out how i can get my entrypoint script copied to the desired path with execute permissions set. </p>