【发布时间】:2022-01-13 16:10:50
【问题描述】:
我在 nginx 反向代理后面有一个 .net core 2.1 api,我在 Visual Studio 中使用 docker compose 设置。运行时,api 是可访问的(我有一个运行状况检查控制器,我可以调用它来验证),但我无法调试。看起来我的解决方案在构建后没有运行。但是我的容器已经启动并且可以访问。我正在使用 Visual Studio 2019。
这是我的文件夹结构:
- ...
- RestApi(项目文件夹文件夹)
- Dockerfile
- docker-compose.yml
- 反向代理(文件夹)
- Dockerfile
- nginx.conf
- ...
这些是文件(文件夹结构从上到下):
Dockerfile(用于 api):
#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:2.1-stretch-slim AS base
WORKDIR /app
#EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["RestApi/RestApi.csproj", "RestApi/"]
COPY ["Services/Services.csproj", "Services/"]
COPY ["DataServices/DataServices.csproj", "DataServices/"]
COPY ["Entities/Entities.csproj", "Entities/"]
RUN dotnet restore "RestApi/RestApi.csproj"
COPY . .
WORKDIR "/src/RestApi"
RUN dotnet build "RestApi.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "RestApi.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_URLS http://+:5000
EXPOSE 5000
ENTRYPOINT ["dotnet", "RestApi.dll"]
docker-compose.yml:
version: '2.1'
services:
restapi:
build:
context: ./
dockerfile: Dockerfile
expose:
- "5000"
#restart: always
reverseproxy:
build:
context: ./ReverseProxy
dockerfile: Dockerfile
ports:
- "80:80"
#restart: always
links :
- restapi
Dockerfile(反向代理):
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
nginx.conf:
worker_processes 4;
events { worker_connections 1024; }
http {
sendfile on;
upstream app_servers {
server RestApi:5000;
#server 172.17.0.1:5000;
}
server {
listen 80;
location / {
proxy_pass http://app_servers;
proxy_redirect off;
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-Host $server_name;
}
}
}
通过 Visual Studio 运行 docker-compose 时,docker 容器已正确创建,但我无法调试,也没有启动浏览器屏幕。在构建或运行时我没有收到任何错误。如果您需要更多信息,请询问。
【问题讨论】:
标签: visual-studio debugging nginx .net-core docker-compose