title: docker-compose build and docker build do not share layer cashing when copying files
body: <p>When I build a multi-stage docker build with <code>docker-compose build</code> the docker layer cashing does not transfer to <code>docker build .</code> command</p>
  
  <p>In the logs provided below you'll see that the <code>WORKDIR</code> command uses the docker layer cashing but <code>COPY</code> ignores it and creates a new hash. (the files have not been changed at all). </p>
  
  <p>This does not occur when I use <strong>only</strong> <code>docker build</code> or <code>docker-compose</code> build.
  Here are the logs of the builds:</p>
  
  <pre><code>T02429:app$ docker images
  REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
  node                10                  9b9d314e0a86        7 hours ago         904MB
  T02429:app$ docker-compose build test
  Building test
  Step 1/6 : FROM node:10 as base
   ---&gt; 9b9d314e0a86
  Step 2/6 : WORKDIR /usr/src/app
   ---&gt; Running in fc2d962f4fd0
  Removing intermediate container fc2d962f4fd0
   ---&gt; 362c0b907170
  Step 3/6 : COPY package.json ./
   ---&gt; 7457757e0221
  Step 4/6 : COPY yarn.lock ./
   ---&gt; 8bb824d2d7cd
  Step 5/6 : COPY jest.config.js ./
   ---&gt; 584c78a1cce8
  Step 6/6 : COPY src src
   ---&gt; 8d7aac67a142
  
  Successfully built 8d7aac67a142
  Successfully tagged test_image:latest
  T02429:app$ docker build -t full_build .
  Sending build context to Docker daemon    255kB
  Step 1/12 : FROM node:10 as base
   ---&gt; 9b9d314e0a86
  Step 2/12 : WORKDIR /usr/src/app
   ---&gt; Using cache
   ---&gt; 362c0b907170
  Step 3/12 : COPY package.json ./
   ---&gt; 48e89caded31
  Step 4/12 : COPY yarn.lock ./
   ---&gt; 58c942524315
  Step 5/12 : COPY jest.config.js ./
   ---&gt; 02b7f45d1d90
  Step 6/12 : COPY src src
   ---&gt; 708fe2761b39
  Step 7/12 : FROM node:10 as prod
   ---&gt; 9b9d314e0a86
  Step 8/12 : WORKDIR /usr/src/app
   ---&gt; Using cache
   ---&gt; 362c0b907170
  Step 9/12 : COPY --from=base /usr/src/app/package.json package.json
   ---&gt; 542eacbc1285
  Step 10/12 : COPY --from=base /usr/src/app/src src
   ---&gt; c40cbe92f9ec
  Step 11/12 : EXPOSE 3000
   ---&gt; Running in 66473d8427c7
  Removing intermediate container 66473d8427c7
   ---&gt; f5b1b1deafab
  Step 12/12 : CMD [ "echo", "hello world" ]
   ---&gt; Running in a8c4609e7159
  Removing intermediate container a8c4609e7159
   ---&gt; 863470696544
  Successfully built 863470696544
  Successfully tagged full_build:latest
  </code></pre>
  
  <p>This is my docker file:</p>
  
  <pre><code># The instructions for the first stage
  FROM node:10 as base
  WORKDIR /usr/src/app
  
  COPY package.json ./
  COPY yarn.lock ./
  COPY jest.config.js ./
  COPY src src
  
  # The instructions for second stage
  FROM node:10 as prod
  WORKDIR /usr/src/app
  
  COPY --from=base /usr/src/app/package.json package.json
  COPY --from=base /usr/src/app/src src
  
  EXPOSE 3000
  CMD [ "echo", "hello world" ]
  </code></pre>
  
  <p>This is my docker-compose.yml</p>
  
  <pre><code>version: '3.7'
  
  services:
    web:
      image: web_image:latest
      build:
        context: .
        target: prod
    test:
      image: test_image:latest
      build:
        context: .
        target: base
      environment:
        - CI=true
      command: echo Hello
  </code></pre>