问题描述
[asp.net core 2.0 和 docker for linux]
[asp.net core 2.0 and docker for linux]
我对 docker 完全陌生,并试图弄清楚在我有 2 个项目的解决方案的情况下如何使用 docker.我见过的所有教程都显示单个项目.
I am completely new to docker and trying to figure out how to use docker in a case where i have a solution with 2 projects. All tutorials i've seen show with single project.
所以,如果有人能展示一步一步的解决方案,我将不胜感激.
So, if someone could show step by step solution i would really appreciate it.
我有一个解决方案结构,如:
i have a solution structure like:
Solution.sln
|______WebAPIProject.csproj
|______ClassLibraryProject.csproj
在 Visual Studio 中,我为解决方案添加了 docker 支持并获得了这些文件:
In Visual studio, i've added docker support to solution and got these files:
在 WebAPIProject 下,它创建了这个 Docker 文件:
Under WebAPIProject, it created this Docker file:
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "WebAPIProject.dll"]
然后,在单独的 docker-compose 'project' 下:
then, under separate docker-compose 'project' i've got:
docker-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
我确信它对路径来说是微不足道的,但我对这一切都感到很迷茫,所以如果有人能对它有所了解吗?
I am sure its something trivial with paths but i am just pretty lost with it all so if someone could shed a bit of a light on it?
推荐答案
我终于找到了如何使用 docker 构建解决方案的方法.
I finally found a way how to built solutions with docker.
重要提示:为此,您必须将 Dockerfile 文件放入解决方案文件所在的同一位置
我刚刚创建了一个包含以下内容的 docker 文件:
I've just created a docker file with the following content:
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"]
请注意,我认为您可能必须尊重项目构建依赖项,但我真的不知道.
Note that I think you may have to respect project build dependencies but I don't know really.
构建调用示例:
sudo docker build --no-cache -t webapi:dev .
要运行的示例调用:
sudo docker run -d=false -p 8080:80 --name webapi webapi:dev
希望有所帮助.
这篇关于asp.net core 2.0 - 多项目解决方案docker文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!