我创建了默认的VS2017 webAPI项目,并为Linux提供了Docker支持。 当我尝试构建映像时,遇到诸如“无法找到... / docker-buildxxxx /”之类的问题,为解决该问题,我将dockerfile向上移动了一层,其中* .sln和.dockerignore文件在其中。
我已经成功构建并运行了该映像,但是我没有运气向容器中提出一些请求。我在所有可能的组合中都使用-p host_port:container_port,但这没用。
仅供参考:如果没有docker,它可以正常工作。 (dotnet test.dll
)
您能提供一些我需要研究的地方吗?或者您能提供确切的解决方案?
docker版本
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"]
答案 0 :(得分:1)
那是我一生中最艰难的两个夜晚,但我找到了解决办法。
问题是由Visual Studio引起的,它生成了错误的dockerfile。
固定的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"]
解决方案来自这里:
https://hub.docker.com/r/microsoft/dotnet-samples/
https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/Dockerfile