Docker:在容器中运行应用程序时无法访问我的本地MongoDB容器

时间:2019-09-28 23:15:18

标签: docker

我已经运行了一个使用容器MongoDB容器作为数据库的python应用程序。

在本地运行控制器应用程序时,我没有访问Mongo数据库的问题。

这是我的应用程序的docker文件。

FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 8000
CMD python ./controller.py

我用下一条命令运行Mongo数据库。

sudo docker run -p 27027:27017 -d --name my-local-db --network local_bridge mongodb

我的申请

sudo docker run -p 8000:8000 -d --name scrapper-controller --network local_bridge scrapper-controller

我已经在docker上检查了我的local_bridge,可以看到两个容器都在同一个网络中。

[
    {
        "Name": "local_bridge",
        "Id": "fa2609918a702e51ecba93920434b992abf98249c90955d6ac700b59a5089166",
        "Created": "2019-09-29T00:46:11.301246442+02:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "bcf382d955e0492991e73a3659e729ea6ddd6b4514809f05bb11e43b92a9ecdb": {
                "Name": "scrapper-controller",
                "EndpointID": "f51340bf27e553b3936ff580ce396896f8d1c14e9d0b81ae3bc869be97106db6",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            },
            "ceaea1d9f6317cd224c2fe96a0ce6fd6e6740661bba2f0bc014f5b55054eab99": {
                "Name": "my-local-db",
                "EndpointID": "95f3cd136d7810b8e168e0e01e0ab9d4667122f058d59ddd2319ada6888434cc",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

有什么想法在这里失败吗?

0 个答案:

没有答案