I've installed Docker for Windows and created a new Asp.net core application with docker support using Visual Studio 2017(I haven't made any change yet). However, docker build reported the following error. Is the Dockerfile correct?
PS C:\source\repos\myProj\ProcessFiles> docker build . Sending build context to Docker daemon 1.178MB Step 1/17 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base ---> 04aae08f15c5 Step 2/17 : WORKDIR /app ---> Using cache ---> 135955e04284 Step 3/17 : EXPOSE 34746 ---> Using cache ---> 85fd0075aa42 Step 4/17 : EXPOSE 44398 ---> Using cache ---> 7e3d5526f601 Step 5/17 : FROM microsoft/dotnet:2.1-sdk AS build ---> 7c3e298d40ac Step 6/17 : WORKDIR /src ---> Using cache ---> b395ba27d8f9 Step 7/17 : COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/ COPY failed: stat /var/lib/docker/tmp/docker-builder662645761/ProcessFiles/ProcessFiles.csproj: no such file or directory
Here is the Dockerfile
automatically generated by Visual Studio. The error occurred on the line COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/
.
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 34746
EXPOSE 44398
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/
RUN dotnet restore ProcessFiles/ProcessFiles.csproj
COPY . .
WORKDIR /src/ProcessFiles
RUN dotnet build ProcessFiles.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish ProcessFiles.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ProcessFiles.dll"]
Here is the Visual Studio output. (The lines about setting AWS were excluded).
Inspecting Dockerfile to figure how to build project and docker image ... Skip building project since it is done as part of Dockerfile Executing docker build ... invoking 'docker build', working folder 'C:\source\repos\myProj\ProcessFiles, docker file C:\source\repos\myProc\ProcessFiles\Dockerfile, image name processfiles:latest' ... docker build: Sending build context to Docker daemon 1.178MB ... docker build: COPY failed: stat /var/lib/docker/tmp/docker-builder225959758/ProcessFiles/ProcessFiles.csproj: no such file or directory ... docker build: Step 1/17 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base ... docker build: ---> 04aae08f15c5 ... docker build: Step 2/17 : WORKDIR /app ... docker build: ---> Using cache ... docker build: ---> 135955e04284 ... docker build: Step 3/17 : EXPOSE 34746 ... docker build: ---> Using cache ... docker build: ---> 85fd0075aa42 ... docker build: Step 4/17 : EXPOSE 44398 ... docker build: ---> Using cache ... docker build: ---> 7e3d5526f601 ... docker build: Step 5/17 : FROM microsoft/dotnet:2.1-sdk AS build ... docker build: ---> 7c3e298d40ac ... docker build: Step 6/17 : WORKDIR /src ... docker build: ---> Using cache ... docker build: ---> b395ba27d8f9 ... docker build: Step 7/17 : COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/ Error executing "docker build" Attempting to clean up any ELB resources created for the failed deployment Unknown error publishing container to AWS
Here are the files in directory C:\source\repos\myProj
. The file Dockerfile
is under C:\source\repos\myProj\ProcessFile\
. Should it be moved one level up?
Mode Name ---- ---- d----- bin d----- obj d----- ProcessFiles -a---- .dockerignore -a---- .gitattributes -a---- .gitignore -a---- docker-compose.dcproj -a---- docker-compose.override.yml -a---- docker-compose.yml -a---- myProc.sln
Seems like VS is generating a bad dockerfile.
The answer provided BMitch is correct in my case as well, however it ends up in another error.
Short story:
COPY
statementCOPY . .
statementLong story:
https://developercommunity.visualstudio.com/content/problem/459905/docker-build-failes-with-dockerfile-created-by-vs.html
When you run the build command
The
.
in that command indicates the "build context" that gets sent to the (possibly remote) docker engine. All of theCOPY
andADD
commands must be from inside this directory (or from a previous stage with multi stage builds). You can also exclude files from this context using the.dockerignore
file. The tmp directory is a uniquely generated internal directory of docker's consisting of this build context.To fix your issue, you need to make sure ProcessFiles/ProcessFiles.csproj exists in the directory where you run your build from, and that you didn't exclude it from the context with the
.dockerignore
file.Edit: based on your comments, change your copy command to: