title: Build docker image using different directory contexts
body: <p>My current project consists of a mongo server, a rabbitmq server and a dotnet core service. It is structured as follows:</p>
  
  <pre><code>.
  ├── project1.docker-compose.yml #multiple docker-compose files for all projects
  ├── .dockerignore
  ├── Util/
  |   └── some common code across all projects
  └── Project1/  #there are multiple projects at the same level with the same structure
      ├── .docker/
      |   ├── mongodb
      |   |   └──Dockerfile
      |   └── rabbitmq
      |       └──Dockerfile
      ├── BusinessLogicClasses/
      |   └── some classes that contain my business logic 
      └── DotNetCoreService/
          ├── my service code 
          └── .docker
              └──Dockerfile
  </code></pre>
  
  <p>Right now I am able to use docker-compose command to build the images for mongodb, rabbitmq and the dot net core succesfully. The docker-compose.yml sits at the home directory level because my different projects (in this case Project1) references code found under the Util directory. Therefore I need to be able to provide a context that is above both directories so that I can use COPY operations on the Dockerfile. </p>
  
  <p>My basic project1.docker-compose.yml is as follows (I excluded not important parts)</p>
  
  <pre><code>version: '3'
  services:
    rabbitmq:
      build: 
        context: Project1/.docker/rabbitmq/
  
    mongodb:    
      build:
         context: Project1/.docker/mongodb/
  
    dotnetcoreservice: 
      build:
        context: ./
        dockerfile: Project1/DotNetCoreService/.docker/Dockerfile
  </code></pre>
  
  <p>As can be seen, the context for the dotnetcoreservice is at the home directory level. Therefore my Dockerfile for that specific image needs to target the full paths from the context as follows:</p>
  
  <pre><code>#escape=`
  FROM microsoft/dotnet:2.0-sdk AS build
  WORKDIR /app
  COPY Project1/ ./Project1/
  COPY Util/ ./Util/
  RUN dotnet build Project1/DotNetCoreService/
  </code></pre>
  
  <p>This dockerfile works succesfully when invoked via the docker-compose command at the home directory level, however when invoked via the <code>docker build .\Project1\DotNetCoreService\.docker\</code> command it fails with the following message:</p>
  
  <blockquote>
    <p>COPY failed: stat
    /var/lib/docker/tmp/docker-builder241915396/Project1: no
    such file or directory</p>
  </blockquote>
  
  <p>I think this is a matter of the actual context because the <code>docker build</code> instruction automatically sets the context to where the Dockerfile is. I would like to be able to use this same directory structure to create images both with the <code>docker-compose build</code> as well as with the <code>docker build</code> instructions.</p>
  
  <p>Is this somehow possible?</p>