title: How to copy from volume mapped opt to image opt folder in docker?
body: <p>Assuming I have a docker image</p>
  <pre><code>FROM openjdk:8-jdk-slim
  WORKDIR /opt
  COPY localfile ../imagefile
  </code></pre>
  <p>I can create my docker image <code>docker build -t my-image .</code> and have my local <code>localfile</code> not the image as <code>../imagefile</code>.</p>
  <p>I can also do this interactively by</p>
  <ol>
  <li>Run <code>docker run -it --name my-container --volume=$(pwd):/opt --workdir=/opt openjdk:8-jdk-slim</code></li>
  <li>Then <code>cp localfile ../imagefile</code></li>
  <li>Then <code>exit</code></li>
  <li>Then create the image by running <code>docker commit my-container my-image</code></li>
  </ol>
  <p>Both produce the equivalent <code>my-image</code>.</p>
  <p>However, if I change my Dockerfile to below</p>
  <pre><code>FROM openjdk:8-jdk-slim
  WORKDIR /opt
  COPY localfile imagefile
  </code></pre>
  <p>I can build the image using the <code>docker build -t my-image .</code>. However, I cannot <code>cp localfile imagefile</code>, because the <code>cp</code> will only copy the file to the original disk volume folder mapped to <code>opt</code> and not the image actual <code>opt</code> folder.</p>
  <p>Is there a way still copy my file to the image <code>opt</code> folder (and not the local one), when my <code>opt</code> is mapped to the local folder?</p>
  <p>Or another way of asking, is there equivalent <code>COPY</code> command I can use when I'm running the container interactively to create the image?</p>