title: How to use Docker's COPY/ADD instructions to copy a single file to an image
body: <p>I am trying to copy a single file from the root of the build context into a newly created directory in a docker image.</p>
  
  <p>The Dockerfile that I am using is as follows:</p>
  
  <pre><code>FROM debian:latest
  RUN mkdir -p /usr/src/app
  WORKDIR /usr/src/app
  COPY test.txt /usr/src/app
  </code></pre>
  
  <p>The test.txt file is a simple ASCII text file as follows:</p>
  
  <pre><code>$ cat test.txt 
  This is a test
  </code></pre>
  
  <p>However, when I build this image I get an image stating that the destination path is not a directory.</p>
  
  <pre><code>$ docker build .
  Sending build context to Docker daemon 4.608 kB
  Sending build context to Docker daemon 
  Step 0 : FROM debian:latest
   ---&gt; 9a61b6b1315e
  Step 1 : RUN mkdir -p /usr/src/app
   ---&gt; Using cache
   ---&gt; 86bd44a8776e
  Step 2 : WORKDIR /usr/src/app
   ---&gt; Using cache
   ---&gt; ed6771adc681
  Step 3 : ADD test.txt /usr/src/app
  stat /var/lib/docker/devicemapper/mnt/ee5b9b7029f2adf27d332cbb0d98d6ad9927629a7569fd2d9574cb767b23547b/rootfs/usr/src/app/test.txt: not a directory
  </code></pre>
  
  <p>I have tried using multiple combinations of docker versions, base images, and distributions with docker installed. I have also tried using ADD instead of COPY but the result is the same.</p>
  
  <p>I am currently trying this on CentOS 7 with the following docker version installed:</p>
  
  <pre><code>Client version: 1.7.1
  Client API version: 1.19
  Go version (client): go1.4.2
  Git commit (client): 786b29d
  OS/Arch (client): linux/amd64
  Server version: 1.7.1
  Server API version: 1.19
  Go version (server): go1.4.2
  Git commit (server): 786b29d
  OS/Arch (server): linux/amd64
  </code></pre>
  
  <p>What I have noticed is that I can copy a directory, but not a file. For example, if I create a "test" directory in the build context root and put test.txt inside the test directory then I can copy the directory successfully:</p>
  
  <pre><code>FROM debian:latest
  RUN mkdir -p /usr/src/app
  WORKDIR /usr/src/app
  COPY test /usr/src/app
  </code></pre>
  
  <p>Note that in the above Dockerfile I copy the entire ./test directory rather than just ./test.txt. This build successfully.</p>
  
  <p>The <a href="https://docs.docker.com/reference/builder/#copy" rel="noreferrer">Docker documentation</a> has the following sample use case for the COPY instruction which is similar to what I am trying to do:</p>
  
  <pre><code>COPY hom?.txt /mydir/
  </code></pre>
  
  <p>Can anyone point out what I am doing wrong? How can I go about copying a single file?</p>