【发布时间】:2020-06-24 05:46:07
【问题描述】:
首先,我是 docker 容器的新手,我不太了解它们是如何运行的,但我有这样的设置:
- 一个 .NET Core API 的 docker 容器(VS-2019 自动生成的 Docker 文件)
- 一个用于 Angular 9 应用程序的 docker 容器
API 可通过https://localhost:44384/api/weatherforecast 访问 可通过 https://localhost:4200
访问容器化的 Angular 应用程序如果我在没有 docker 的情况下运行 angular 应用程序,在使用代理修复 CORS 问题后,我可以连接到 https://localhost:44384/api/weatherforecast。但是,当我运行 dockerized 版本时,我收到以下错误:
Failed to load resource: the server responded with a status of 504 (Gateway Timeout)
在 VS 控制台我看到这个错误:
clearance_1 | [HPM] Error occurred while trying to proxy request /api/weatherforecast from loccoalhost:4200 to https://localhost:44384 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
这似乎是一个连接问题,所以我在互联网上挖掘了一下,我试图将这两个容器放在同一个网络下。
以下是步骤: 1.创建一个桥接“测试”网络
docker network create test
- 将两个容器连接到新创建的网络:
docker 网络连接测试 [容器 id 1]
docker 网络连接测试 [容器 id 2]
- 如果我检查网络,一切似乎都很好,但 api 仍然无法在 localhost 上调用
其他潜在有用的东西:
docker-compose.yml:
version: "3.7"
services:
clearance:
build:
# network: host
context: .
dockerfile: DockerFileLocal
ports:
- 4200:4200
volumes:
- /app/node_modules
- .:/app
proxy.conf.json
{
"/api/*": {
"target": "https://localhost:44384",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
我错过了什么?
【问题讨论】:
-
你是如何开始
apidocker container 的? -
不确定 Visual Studio 如何启动容器。这些是启动配置: "Docker": { "commandName": "Docker", "launchBrowser": true, "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/weatherforecast", " environmentVariables": { "ASPNETCORE_URLS": "https://+:443;http://+:80", "ASPNETCORE_HTTPS_PORT": "44384" }, "httpPort": 52012, "useSSL": true, "sslPort" : 44384 }
标签: angular docker docker-compose docker-networking core-api