0

I have made a asp.net core 2.0 web API. Now I want to create a docker image for this API.

Here is my docker file content -

    FROM  microsoft/aspnetcore:2.0-nanoserver-1803 AS build-env
WORKDIR /app

FROM microsoft/aspnetcore-build:2.0-nanoserver-1803 AS base
WORKDIR /src

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM base AS final
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Microservice_Orders.dll"]

I am running the following command to create an image

docker build -t ms_orders .

But I am getting following error on execution.

******Step 11/12 : COPY --from=build-env /app/out . COPY failed: CreateFile \?\Volume{a3251a00-f8f4-4510-8db2-f495f33ce178}\app\out:

The system cannot find the file specified.******

1 Answer 1

1

I found a few things to be a bit strange in that dockerfile.

It looks like you have base and build-env mixed up, i.e. you're building into base, but then trying to copy what you built from build-env.

Also the path from dotnet publish doesn't match the path in COPY --from=build-env. /src/out (I think) vs /app/out

I would try to change it to below. I have copied the dockerfile and commented where I've made changes.

FROM  microsoft/aspnetcore:2.0-nanoserver-1803 AS base  # name changed since this is your base
WORKDIR /app
EXPOSE 80   # You'll probably also need to expose the app on some port(s)
EXPOSE 443  # depending on if you want https or not, you can remove one of these lines

FROM microsoft/aspnetcore-build:2.0-nanoserver-1803 AS build-env # name changed since this is where you build
WORKDIR /src

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o /app/out           # output path changed!

# Build runtime image
FROM base AS final
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Microservice_Orders.dll"]

Disclaimer: I haven't actually tried to build it, so there could be a few more issues.

Sign up to request clarification or add additional context in comments.

4 Comments

Just a sidenote, not really related to your question: The base docker image you are using (microsoft/aspnetcore:2.0* from Docker Hub) has been deprecated, since dotnet core 2.0 is no longer supported by Microsoft. You might want to look into migrating your application to a newer version of dotnet core.
Thanks. .. It worked. If you could also explain the steps meaning - that would be great. As I am new to using docker
Great! I think this article describes multi-stage builds very well: docs.docker.com/develop/develop-images/multistage-build Let me know if it's still unclear after reading through that
Basically, the purpose of splitting the dockerfile into several stages (base, build-env, and final) is to reduce the size of the final docker image. Note that we copy all the source code in the build-env stage, but we only include what is needed to run the application in the final image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.