This is the Dockerfile generated by VS2017. I changed a little bit for using it on Azure DevOps
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["WebApi.csproj", "WebApi/"]
COPY ["./MyProject.Common/MyProject.Common.csproj", "MyProj.Common/"]
RUN dotnet restore "MyProject.WebApi/MyProject.WebApi.csproj"
COPY . .
WORKDIR "/src/MyProject.WebApi"
RUN dotnet build "MyProject.WebApi.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "MyProject.WebApi.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyProject.WebApi.dll"]
Solution structure
MyProject.sln
-MyProject.Common
...
-MyProject.WebApi
...
Dockerfile
I have created a Build Pipeline under Azure DevOps to run Docker Build with these steps :
- Get Sources Step from Azure Repos Git
- Agent Job (Hosted Ubuntu 1604)
- Command Line script
docker build -t WebApi .
I have this error
2019-02-02T18:14:33.4984638Z ---> 9af3faec3d9e
2019-02-02T18:14:33.4985440Z Step 7/17 : COPY ["./MyProject.Common/MyProject.Common.csproj", "MyProject.Common/"]
2019-02-02T18:14:33.4999594Z COPY failed: stat /var/lib/docker/tmp/docker-builder671248463/MyProject.Common/MyProject.Common.csproj: no such file or directory
2019-02-02T18:14:33.5327830Z ##[error]Bash exited with code '1'.
2019-02-02T18:14:33.5705235Z ##[section]Finishing: Command Line Script
Attached Screenshot with the working directory used
I don't understand if I have to change something inside Dockerfile or into Console Script step on DevOps
This is just a hunch, but considering your
Dockerfile
is located underMyProject.WebApi
and you want to copy files fromMyProject.Common
which is on the same level, then you might need to specify a different context root directory when runningdocker build
:When Docker builds an image it collects a context - a list of files which are accessible during build and can be copied into image.
When you run
docker build -t WebApi .
it runs insideMyProject.WebApi
directory and all files in the directory.
(unless you have.dockerignore
file), which isMyProject.WebApi
in this case, are included into context. ButMyProject.Common
is not part of the context and thus you can't copy anything from it.Hope this helps
EDIT: Perhaps you don't need not specify
Working Directory
(shown in the screenshot), then the command would change into:In this case Docker will use
Dockerfile
located insideMyProject.WebApi
and include all files belonging to the solution into the context.You can also read about context in the Extended description for the
docker build
command in the official documentation.