【发布时间】:2020-07-14 01:55:40
【问题描述】:
我在 .NET Core 3.1 的两个独立 API 项目中使用 docker-compose
- ContainerAuth(运行 Auth API 的容器)
- ContainerAppApi(用于单独应用的 API)
ContainerAuth 有一个我需要从 ContainerAppApi
访问的端点ContainerAuth上的端点
POST:http://locahost:5000/auth/validate
我的 ContainerAppApi 在单独的 docker 容器中运行(完全不同的 repo/project/etc..)。这是在http://localhost:5100上运行的
问题 从 ContainerAppApi -> ContainerAuth 发出请求时,我收到以下异常:
无法分配请求的地址 无法分配请求的地址
根据我的阅读,问题是 ContainerAppApi 不知道 ContainerAuth 的 Api 在 http://localhost:5000
我以为我可以建立一个桥接网络,但我仍然得到同样的错误。我已经验证两个容器都连接到我的桥接网络,所以,我是否缺少某种端口绑定?还是我缺少网络过程中的一些额外步骤?
docker-compose 用于 ContainerAuth
version: '3.4'
services:
web:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
build:
context: ..
dockerfile: Dockerfile
ports:
- 5000:80
- 5001:443
networks:
- my-network
networks:
my-network:
driver: bridge
external: true
docker-compose 用于 ContainerAppApi
version: '3.4'
services:
web:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
build:
context: ..
dockerfile: Dockerfile
ports:
- 5100:80
- 5101:443
networks:
- my-network
networks:
my-network:
driver: bridge
external: true
docker network ls
NETWORK ID NAME DRIVER SCOPE
23179718cd0a bridge bridge local
431eba987024 host host local
733c83d6dee2 my-network bridge local
2bf6118b71a4 none null local
docker network 检查我的网络
[
{
"Name": "my-network",
"Id": "733c83d6dee2d8ffb007bdb99324e9312a07d5735d329059a2083a11c1582642",
"Created": "2020-07-11T02:28:09.2078715Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.21.0.0/16",
"Gateway": "172.21.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"741624d9304add4d39bc0dc30b04af2fc26a36e87565d87ac5eca44b2a2e361e": {
"Name": "ContainerAppApi_web_1",
"EndpointID": "623a99e45344ef52c8352fa1a35a6f02c8417107d85bccae6a06289c73b0d4c5",
"MacAddress": "02:42:ac:15:00:03",
"IPv4Address": "172.21.0.3/16",
"IPv6Address": ""
},
"74c08686a62f6028a74796c41f4b2fcfe9e6818588783c3ab0e76665acd032d7": {
"Name": "ContainerAuth_web_1",
"EndpointID": "6bb7a30f2d231514a3569481de166d46c30c78b70b725e5ee595d027dab1639f",
"MacAddress": "02:42:ac:15:00:02",
"IPv4Address": "172.21.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
看起来一切都已连接,但是 ContainerAppApi 不能调用 ContainerAuth 的 API 吗?两者都已启动并正在运行,我可以使用 Postman 访问每个 api。
【问题讨论】:
标签: docker .net-core docker-compose docker-networking docker-network