title: Understanding multi stage DockerFile builds
body: <p>I am new to Docker. I have the following directory structure for my project</p>
  <pre><code>docker-compose.yml
  |-services
    |-orders
      |-DockerFile
  </code></pre>
  <p>I am using standard ASP.Net Core DockerFile that has the following content:</p>
  <pre><code>FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
  WORKDIR /app
  EXPOSE 80
  
  FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
  WORKDIR /src
  COPY [&quot;Services/Orders/Orders.csproj&quot;, &quot;Services/Orders/&quot;]
  RUN dotnet restore &quot;Services/Orders/Orders.csproj&quot;
  COPY . .
  WORKDIR &quot;/src/Services/Orders&quot;
  RUN dotnet build &quot;Orders.csproj&quot; -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish &quot;Orders.csproj&quot; -c Release -o /app/publish
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  ENTRYPOINT [&quot;dotnet&quot;, &quot;Orders.dll&quot;]
  </code></pre>
  <p>My docker-compose.yml file has</p>
  <pre><code># Please refer https://aka.ms/HTTPSinContainer on how to setup an https developer certificate for your ASP .NET Core service.
  version: &quot;3.4&quot;
  
  services:
    orders-api:
      image: orders-api
      build:
        context: .
        dockerfile: Services/Orders/Dockerfile
      ports:
        - &quot;2222:80&quot;
  </code></pre>
  <p>I have some confusion with these two files</p>
  <ul>
  <li><p><strong>Question 1:  What is the use of WORKDIR /app on line number 2?</strong></p>
  <p>My understanding is that we are using a base image that we can extend so
  when we import the base image in line number 1 and then set the
  WORKDIR and port in line number 2 and 3, will they be used by following commands
  that use this image?</p>
  </li>
  <li><p><strong>Question 2: Why are we setting <strong>WORKDIR /src</strong> for the SDK image and not <strong>WORKDIR /app</strong></strong>?</p>
  </li>
  <li><p><strong>Question 3: Are paths in copy commands relevant to Dockerfile or Docker-compose.yml file?</strong></p>
  <p>In the line COPY [&quot;Services/Orders/Orders.csproj&quot;, &quot;Services/Orders/&quot;], the path that we are specifying seems to be relevant to the docker-compose.yml file and not the DockerFile which is nested down further in folders. Does this mean that paths in Dockerfile need to be relevant to docker-compose.yml? I am asking this because I am thinking that if I run the docker build command using this Dockerfile then I will get an error since the path in the copy command will not be valid.</p>
  </li>
  </ul>