1

I have create default VS2017 webAPI project with docker support for Linux. When i had try to build image I met problem like "unable to find .../docker-buildxxxx/" , to solve it i moved dockerfile on one level up, where is *.sln and .dockerignore file are.

I had successfully build and run that image, but i have no luck to take some request into container. I use -p host_port:container_port in all possible combinations, but it is useless.

FYI: without docker it works fine. (dotnet test.dll)

Can you provide some point where i have to research or can you provide exact solution ?

docker version

Client: Docker Engine - Community
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:47:51 2018
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:52:55 2018
  OS/Arch:          linux/amd64
  Experimental:     false

docker run -t service --port 8080:80 --name myfirst_container

warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {71f5b198-2cbb-45ba-a7fc-a36df9f8b985} may be persisted to storage in unencrypted form.

Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.

DOCKERFILE

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["test/test.csproj", "test/"]
RUN dotnet restore "test/test.csproj"
COPY . .
WORKDIR "/src/test"
RUN dotnet build "test.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "test.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "test.dll"]
2
  • Can you include your Dockerfile into your question? Commented Nov 20, 2018 at 0:12
  • @ug_ done. It is auto generated dockerfile by VS. Commented Nov 20, 2018 at 8:57

1 Answer 1

1

It was the two hardest nights in my life, but i get a solution.

Problem was caused by Visual studio, it generate wrong dockerfile.

Fixed dockerfile

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.sln .
COPY test/*.csproj ./test/
RUN dotnet restore

# copy everything else and build app
COPY test/. ./test/
WORKDIR /app/test
RUN dotnet publish -c Release -o out


FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
WORKDIR /app
COPY --from=build /app/test/out ./
ENTRYPOINT ["dotnet", "test.dll"]

Solution came from here:

https://hub.docker.com/r/microsoft/dotnet-samples/

https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/Dockerfile

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

2 Comments

I think the problem wasnt that it generated the wrong docker file but that you moved it one directory up. It was copying . . so the entire solution. You had it copy only the one project causing unintended side effects. IMO you should keep the docker file at the location it was generated and modify it to your needs. Thanks for posting your solution back tho!
With generated dockerfile, docker even does not build an 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.