Open lolik20 opened 2 years ago
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
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
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;
}
}
}
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"]
How i can build container with 2 projects?