我使用引用:https://docs.docker.com/engine/examples/dotnetcore/#prerequisites创建以下Dockerfile
:
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# 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 microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
但是我有以下解决方案结构:
.sln
Dockerfile
------------WebAPP
------------WebAPP.Domain
然后我修改了Dockerfile
,以便我可以定位我的WebAPP csproj等。
FROM microsoft/aspnetcore-build AS builder
WORKDIR /app
# copy csproj and restore as distinct layers
COPY ./WebAPP/*.csproj ./
RUN dotnet restore
# copy everything else and build
COPY ./WebAPP ./
RUN dotnet publish -c Release -o out
# build runtime image
FROM microsoft/aspnetcore
WORKDIR /app
COPY --from=builder /app/out ./
ENV ASPNETCORE_ENVIRONMENT Production
ENTRYPOINT ["dotnet", "WebAPP.dll"]
然而,它在dotnet publish
步骤失败,因为它缺乏可以理解的域项目。我还添加了RUN dotnet build
步骤,以确保我拥有所有依赖项和dll,并且我在倒数第二步确实失败了:
Step 10/12 : COPY --from=builder /app/out ./
COPY failed: stat /var/lib/docker/aufs/mnt/9b7dda771a5bf433365f513a2bfe4cfae4199402b35c95d5f81c57367cdbb788/app/out: no such file or directory
这里有什么我想念的吗?
答案 0 :(得分:0)
如果 WebApp 引用了 WebApp.Domain ,则可以简化DockerFile
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "WebApp.dll"]