[asp.net核心2.0和
linux的docker]
我对Docker完全陌生,并试图在我有2个项目的解决方案的情况下弄清楚如何使用docker.我见过的所有教程都展示了单个项目.
我有一个解决方案结构,如:
Solution.sln |______WebAPIProject.csproj |______ClassLibraryProject.csproj
在Visual Studio中,我已经为解决方案添加了docker支持并获得了以下文件:
在WebAPIProject下,它创建了这个Docker文件:
FROM microsoft/aspnetcore:2.0 ARG source WORKDIR /app EXPOSE 80 COPY ${source:-obj/Docker/publish} . ENTRYPOINT ["dotnet","WebAPIProject.dll"]
然后,在单独的docker-compose’项目’下我得到了:
泊坞窗,compose.ci.build.yml
version: '3' services: ci-build: image: microsoft/aspnetcore-build:1.0-2.0 volumes: - .:/src working_dir: /src command: /bin/bash -c "dotnet restore ./Solution.sln && dotnet publish ./Solution.sln -c Release -o ./obj/Docker/publish"
和docker.compose.yml文件
version: '3' services: WebAPIProject: image: WebAPIProject build: context: ./WebAPIProject dockerfile: Dockerfile
我确信它对于路径来说是微不足道的,但我只是迷失了所有这一切,所以如果有人可以对它有所了解?
解决方法
我终于找到了一种如何使用docker构建解决方案的方法.
FROM microsoft/aspnetcore:2.0 AS base WORKDIR /app EXPOSE 80 FROM microsoft/aspnetcore-build:2.0 AS build WORKDIR /src COPY Solution.sln ./ COPY ClassLibraryProject/*.csproj ./ClassLibraryProject/ COPY WebAPIProject/*.csproj ./WebAPIProject/ RUN dotnet restore COPY . . WORKDIR /src/ClassLibraryProject RUN dotnet build -c Release -o /app WORKDIR /src/WebAPIProject RUN dotnet build -c Release -o /app FROM build AS publish RUN dotnet publish -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet","WebAPIProject.dll"]
请注意,我认为您可能必须尊重项目构建依赖项,但我真的不知道.
示例调用构建:
sudo docker build --no-cache -t webapi:dev .
要运行的示例调用:
sudo docker run -d=false -p 8080:80 --name webapi webapi:dev
希望有所帮助.