Docker-同一网络上的容器之间的通信失败

时间:2018-10-10 00:08:29

标签: django angular docker networking containers

我正在Digital Ocean Droplet上部署Angular-Django应用程序。它由3个Docker容器组成:

  • cards_front:Angular前端
  • cards_api:Django rest框架后端
  • cards_db:postgres数据库

它们都在同一个网络上

[
{
    "Name": "ivan_cards_api_network",
    "Id": "ddbd3524e02a7c918f6e09851731e015fdb7e8647358c5ed0c4cd949cf651fd9",
    "Created": "2018-10-09T23:44:33.293036243Z",
    "Scope": "local",
    "Driver": "bridge",
    "EnableIPv6": false,
    "IPAM": {
        "Driver": "default",
        "Options": null,
        "Config": [
            {
                "Subnet": "172.22.0.0/16",
                "Gateway": "172.22.0.1"
            }
        ]
    },
    "Internal": false,
    "Attachable": true,
    "Ingress": false,
    "ConfigFrom": {
        "Network": ""
    },
    "ConfigOnly": false,
    "Containers": {
        "0d3144b27eaf6d7320357b6d703566e489f672b09b61dba0caf311c6e1c4711c": {
            "Name": "cards_front",
            "EndpointID": "47b1f8f42c4d18afeafeb9da502fd0197e726f29bd6d3d3c2960b44737bd579a",
            "MacAddress": "02:42:ac:16:00:04",
            "IPv4Address": "172.22.0.4/16",
            "IPv6Address": ""
        },
        "3e9233f4bfc023632aaf13a146d1a50f75b4944503d9f226cf81140e92ccb532": {
            "Name": "cards_api",
            "EndpointID": "34d4780dc6f907a8cb9621223d6effe0a0aac1662d5272ae4a5104ba7f3808c4",
            "MacAddress": "02:42:ac:16:00:03",
            "IPv4Address": "172.22.0.3/16",
            "IPv6Address": ""
        },
        "e5e208a20523c2d41433b850dc64db175de8ee7d0d156e2917c12fd8ebdf97ab": {
            "Name": "cards_db",
            "EndpointID": "8a8f44bbcdf2f95e716e2763e33bed31e1d2bdbfae7f6d78c8dee33de426a7ef",
            "MacAddress": "02:42:ac:16:00:02",
            "IPv4Address": "172.22.0.2/16",
            "IPv6Address": ""
        }
    },
    "Options": {},
    "Labels": {
        "com.docker.compose.network": "cards_api_network",
        "com.docker.compose.project": "ivan",
        "com.docker.compose.version": "1.22.0"
    }
}

django设置上的ALLOWED_HOSTS设置为['*']

在浏览器上测试Angular前端时,我会使用Chrome的开发人员工具:

GET http://localhost:8000/themes net::ERR_CONNECTION_RESET

因此,Angular容器无法与django容器通信。

但是,如果我从DO液滴内部执行curl localhost:8000 / themes,则会收到响应。

我知道网络配置中缺少某些内容,但是我无法弄清楚它是什么。

谢谢

编辑:

如果我从Angular容器内部到django容器进行卷曲,则会收到响应(空数组):

root@90cea47dd13d:/# curl 172.22.0.3:8000/themes
[]

0 个答案:

没有答案