none
Docker in a solution with many projects? RRS feed

  • Question

  • Hi all,

    Anyone knows how to create a docker image from a solution with many projects?

    In C#, I have a solution with one project for the Front (web) and another for the Back (api).

    Creating 2 dockers, one for the front and another for the back, it's works fine, but, how can I do for unify both in a unique docker? Is it possible?

    My Dockerfile for Front (web):

    FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
    WORKDIR /app
    EXPOSE 5000
    
    FROM microsoft/dotnet:2.1-sdk AS build
    
    WORKDIR /src
    COPY NuGet.Config ./
    
    COPY myproject.web/app.config myproject.web/
    .....
    
    COPY myproject.public/myproject.public.csproj myproject.public/
    COPY myproject.web/myproject.web.csproj myproject.web/
    RUN dotnet restore myproject.web/myproject.web.csproj
    
    COPY . .
    WORKDIR /src/myproject.web
    RUN dotnet build myproject.web.csproj -c Release -o /app
    
    FROM build AS publish
    RUN dotnet publish myproject.web.csproj -c Release -o /app
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app .
    ENTRYPOINT ["dotnet", "myproject.web.dll"]

    My Dockerfile for Back (api):

    FROM microsoft/dotnet:2.2-runtime AS base
    WORKDIR /app
    
    FROM microsoft/dotnet:2.2-sdk AS build
    WORKDIR /src
    COPY NuGet.config ./
    COPY myproject/appsettings.debug.json myproject/
    ....
    
    COPY myproject/myproject.csproj myproject/
    COPY myproject.dominio/myproject.back.csproj myproject.back/
    COPY myproject.public/myproject.public.csproj myproject.public/
    RUN dotnet restore myproject/myproject.csproj
    COPY . .
    WORKDIR /src/myproject
    RUN dotnet build myproject.csproj -c Release -o /app
    
    FROM build AS publish
    RUN dotnet publish myproject.csproj -c Release -o /app
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app .
    ENTRYPOINT ["dotnet", "myproject.dll"]

    Thanks in advance!





    • Edited by ros2015 Friday, May 24, 2019 2:03 PM refactor
    Thursday, May 23, 2019 11:18 AM

All replies

  • I answer myself, it's quite easy:


    version: '3.4'
    
    services:
      myproject.back:
        image: back
        build:
          context: .
          dockerfile: myproject.back/Dockerfile
    
      myproject.front:
        image: front
        build:
          context: .
          dockerfile: myproject.front/Dockerfile




    Friday, May 24, 2019 1:59 PM