title: Docker build adding empty directories when specifying Dockerfile location?
body: <p>I'm running into an unexpected behavior in Docker when building an image using a Dockerfile from a subdirectory of the context I'm building from, ie:</p>
  
  <pre><code>docker build -t test -f build/docker/golang/Dockerfile .
  </code></pre>
  
  <p>For sanity, I've removed pretty much everything from the Dockerfile, except for the following:</p>
  
  <pre><code>FROM golang:1.12-alpine3.9 AS builder
  RUN apk add tree
  WORKDIR /build/dir
  COPY . .
  RUN tree -a
  </code></pre>
  
  <p>Then, with a <code>.dockerignore</code> of:</p>
  
  <pre><code>*
  !cmd
  !pkg
  </code></pre>
  
  <p>I run, and get the following output:</p>
  
  <pre><code>$ docker build --no-cache -f build/docker/golang/Dockerfile .
  Sending build context to Docker daemon  10.75kB
  Step 1/5 : FROM golang:1.12-alpine3.9 AS builder
   ---&gt; d4953956cf1e
  Step 2/5 : RUN apk add tree
   ---&gt; Running in 20bbaf5ce5b9
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
  (1/1) Installing tree (1.8.0-r0)
  Executing busybox-1.29.3-r10.trigger
  OK: 6 MiB in 16 packages
  Removing intermediate container 20bbaf5ce5b9
   ---&gt; f93961f78847
  Step 3/5 : WORKDIR /build/dir
   ---&gt; Running in e8637288cf26
  Removing intermediate container e8637288cf26
   ---&gt; 90473d72f983
  Step 4/5 : COPY . .
   ---&gt; aeec506ba056
  Step 5/5 : RUN tree -a
   ---&gt; Running in fa652d2cdf65
  .
  ├── build
  │   └── docker
  │       └── golang
  ├── cmd
  │   ├── api
  │   │   └── main.go
  │   └── worker
  │       └── main.go
  └── pkg
      └── math
          ├── math.go
          └── math_test.go
  
  8 directories, 4 files
  Removing intermediate container fa652d2cdf65
   ---&gt; ef761dfd7e4e
  Successfully built ef761dfd7e4e
  </code></pre>
  
  <p>So, to my question: What gives with the empty, but existing <code>build/docker/golang</code> directories? I can put stuff in them, nothing comes through, the <code>Dockerfile</code> isn't there, yet the directories exist... empty.. taunting me.</p>
  
  <p>This doesn't occur if I move the <code>Dockerfile</code> into the root of the project (ie, <code>docker build .</code>, but that doesn't actually fix my problem, and isn't an option for this projects needs.</p>