Visual studio 调试不需要';t使用VisualStudio为docker compose工作
我在nginx反向代理后面有一个.NETCore2.1API,我在VisualStudio中使用DockerCompose设置了该代理。运行时,api是可访问的(我可以调用健康检查控制器进行验证),但无法调试。看起来我的解决方案在构建之后没有运行。但我的集装箱已经准备好了。我正在使用VisualStudio2019 这是我的文件夹结构:Visual studio 调试不需要';t使用VisualStudio为docker compose工作,visual-studio,debugging,nginx,.net-core,docker-compose,Visual Studio,Debugging,Nginx,.net Core,Docker Compose,我在nginx反向代理后面有一个.NETCore2.1API,我在VisualStudio中使用DockerCompose设置了该代理。运行时,api是可访问的(我可以调用健康检查控制器进行验证),但无法调试。看起来我的解决方案在构建之后没有运行。但我的集装箱已经准备好了。我正在使用VisualStudio2019 这是我的文件夹结构: RestApi(项目文件夹) Dockerfile docker-compose.yml ReverseProxy(文件夹) Dockerfile ngi
- RestApi(项目文件夹)
- Dockerfile
- docker-compose.yml
- ReverseProxy(文件夹)
- Dockerfile
- nginx.conf
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(反向代理):
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容器已正确创建,但我无法调试,并且未启动浏览器屏幕。我在构建或运行时没有错误。如果您需要更多信息,请询问。我发现了问题所在。答案是发布在这里的问题的解决方案。 基本上,当dockerfile与相应的csproj文件(项目文件)相邻时,visual studio不会附加调试器。这是出于设计考虑的,因为可能存在您想要启动但不想调试的容器(反向代理、mysql数据库等)。因此,当我将api的Dockerfile移到restapi文件夹(与csproj文件相同的文件夹)中并调整docker-compose.yml以查找该文件夹中的Dockerfile时,visual studio中的调试工作正常
FROM nginx
COPY nginx.conf /etc/nginx/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;
}
}
}