Asp.net core 2.0 - docker file with multiple projects

[asp.net core 2.0 and docker for Linux]

I am completely new to docker and trying to figure out how to use docker when I have a solution with two projects. All the tutorials I've seen show one project.

So, if someone can show a step-by-step solution, I would really appreciate it.

I have a solution structure like:

Solution.sln
|______WebAPIProject.csproj
|______ClassLibraryProject.csproj

In Visual Studio, I added docker support for the solution and got these files:

In WebAPIProject, he created this Docker file :

FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "WebAPIProject.dll"]

then in a separate project file "docker-compose" I have:

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"

and file docker.compose.yml

version: '3'

services:
  WebAPIProject:
    image: WebAPIProject
    build:
      context: ./WebAPIProject
      dockerfile: Dockerfile

I'm sure this is something trivial with paths, but I just lost it all, so if someone can shed light on it?

+13
4

, .

: , 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

, .

+11

, dotnet Windows, Visual Studio, , Microsoft Visual Studio ( 2017 ).

  1. -.
  2. .
  3. " ". .

-, .

: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/visual-studio-tools-for-docker?view=aspnetcore-2.1#existing-app

- Docker, Hyper-V Services " Windows" ( Windows Features ""), , . .

enter image description here

+10
FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

RUN mkdir /output

# Copy project and publish

COPY . /app

WORKDIR /app/YourProjectName
RUN dotnet publish --configuration Debug --output /output

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime

ENV ASPNETCORE_URLS http://*:5001

WORKDIR /app

COPY --from=build-env /output .
EXPOSE 5001

ENTRYPOINT ["dotnet", "YourProjectName.dll"]

Docker, . ASP.NET Core 2 WebApi .

Then run it using  docker run -d -p 8080:5001 --name some-name yourpojectname

Hope this helps someone.

+1
source

This is a link to an awesome post on how to solve this problem.

It mentions the placement of all your code in a directory src. I did not do this, and this is the file I came up with: ( for filepart key for file. I'm sure this is not the best dockerfile otherwise; tips are welcome.)

FROM microsoft/dotnet:2.2-aspnetcore-runtime-stretch-slim AS base
WORKDIR /app
EXPOSE 5000

FROM microsoft/dotnet:2.2-sdk-stretch AS build
WORKDIR /src

COPY ./*.sln ./

COPY */*.csproj ./
RUN for file in $(ls *.csproj); do mkdir -p ${file%.*} && mv $file ${file%.*}; done
RUN dotnet restore

COPY . ./
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 .

ENV ASPNETCORE_URLS="http://*:5000"
ENTRYPOINT ["dotnet", "PersonalSiteApi.dll"]
0
source

Source: https://habr.com/ru/post/1688707/


All Articles