Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with 2 projects #1

Open
lolik20 opened this issue Jul 6, 2022 · 4 comments
Open

Build with 2 projects #1

lolik20 opened this issue Jul 6, 2022 · 4 comments

Comments

@lolik20
Copy link

lolik20 commented Jul 6, 2022

How i can build container with 2 projects?

FROM mcr.microsoft.com/dotnet/core/aspnet:6.0-alpine AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:6.0-alpine AS build
WORKDIR /src
COPY ["RentServiceApp.csproj", "./"]
COPY ["RentServiceCommon.csproj", "./"]

RUN dotnet restore "./RentServiceApp.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "RentServiceApp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "RentServiceApp.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_URLS http://*:5000
ENTRYPOINT ["dotnet", "RentServiceApp.csproj"]
Building api
Step 1/17 : FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
 ---> e3f3ae957ae9
Step 2/17 : WORKDIR /app
 ---> Using cache
 ---> e075be1c0883

Step 3/17 : FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
 ---> 1f349786b71f
Step 4/17 : WORKDIR /src
 ---> Using cache
 ---> 8c4e004fccc2
Step 5/17 : COPY ["RentServiceApp.csproj", "./"]
 ---> Using cache
 ---> e44973d1a797
Step 6/17 : COPY ["RentServiceCommon.csproj", "./"]
ERROR: Service 'api' failed to build: COPY failed: file not found in build context or excluded by .dockerignore: stat RentServiceCommon.csproj: file does not exist

image

@lolik20
Copy link
Author

lolik20 commented Jul 6, 2022

version: "3.7"

services:
  reverseproxy:
    image: lolik20/proxy
    build:
      context: ./Nginx
      dockerfile: Dockerfile
    ports:
      - "80:80"
      - "443:443"
    restart: always

  api:
    image: lolik20/api
    depends_on:
      - reverseproxy
    build:
      context: ./RentServiceApp
      dockerfile: Dockerfile
    expose:
      - "5000"
    restart: always

@soondook
Copy link

soondook commented Nov 5, 2022

Hi guys!
maybe my solution will help someone. I still did not understand what the reason was, but by experiment, I got a working configuration. My problem was that the assembly of two images (via compose) worked correctly for me only when I launched the solution through Visual Studio. When I tried to build via "docker-compose -f docker-compose.yml up -d", the reverse proxy did not work correctly. Below I give examples of my working configs:
P.S. You also need to take into account that the basic images (which are referenced in the example) have changed a long time ago:
for build: microsoft.com/dotnet/core/sdk:3.1-buster AS build

@soondook
Copy link

soondook commented Nov 5, 2022

nginx.conf

worker_processes 1;

events { worker_connections 1024; }

http {

    sendfile on;

    upstream web-api {
        server helloaspnetcore3.api:80;
    }

    server {
        listen 80;
        server_name localhost;

        location / {
            return 301 https://$host$request_uri;
        }
    }

    server {
        listen 443 ssl;
        server_name localhost;

        ssl_certificate /etc/ssl/certs/localhost.crt;
        ssl_certificate_key /etc/ssl/private/localhost.key;

        location / {
            proxy_pass         http://web-api;
            proxy_redirect     off;
            proxy_http_version 1.1;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   X-Forwarded-Host $server_name;
        }
    }
}

@soondook
Copy link

soondook commented Nov 5, 2022

docker-compose.yml

version: '3.4'

services:

  helloaspnetcore3.api:
    depends_on:
      - proxy
    image: ${DOCKER_REGISTRY-}helloaspnetcore3api
    build:
      context: .
      dockerfile: HelloAspNetCore3.Api/Dockerfile
    ports:
      - 5000:80

  proxy:
    build:
      context: ./Nginx
      dockerfile: Nginx.Dockerfile
    ports:
      - "80:80"
      - "443:443"
    restart: always

Dockerfile

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["HelloAspNetCore3.Api/HelloAspNetCore3.Api.csproj", "HelloAspNetCore3.Api/"]
RUN dotnet restore "HelloAspNetCore3.Api/HelloAspNetCore3.Api.csproj"
COPY . .
WORKDIR "/src/HelloAspNetCore3.Api"
RUN dotnet build "HelloAspNetCore3.Api.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "HelloAspNetCore3.Api.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HelloAspNetCore3.Api.dll"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants