【问题标题】:docker compose network not serving reqeusts from hostdocker compose network 不服务来自主机的请求
【发布时间】:2021-10-28 05:57:57
【问题描述】:

[docker-compose 问题]

大家好!我已经被困了一段时间,所以希望我们可以一起调试。

我正在使用 docker compose 来启动三个独立的服务。 一切都建立起来很棒。应用程序的健康检查通过,服务相互联系,但我似乎无法从主机卷曲我的应用程序。

我已经为 app.ports 尝试了以下值:

“127.0.0.1:3000:3000” “3000:3000” "0.0.0.0:3000:3000"

我也尝试使用“主机”网络运行它,但这似乎也不起作用,我不喜欢它,因为显然 Mac 不支持它,而我的本地开发人员环境是 Macosx。产品服务器是 ubuntu。

我已经尝试明确定义默认的网桥网络:

networks:
    default:
        driver: bridge

这是我的 docker-compose.yml

version: "2.4"
services:
    rabbitmq:
        image: rabbitmq
        volumes:
            - ${ML_FILE_PATH}/taskqueue/config/:/etc/rabbitmq/
        environment:
            LC_ALL: "C.UTF-8"
            LANG: "C.UTF-8"
    celery-worker:
        image: ${ML_IMAGE_NAME}
        entrypoint: "celery --broker='amqp://<user>:<password>@rabbitmq:5672//' -A taskqueue.celeryapp worker --uid 1111"
        runtime: ${RUNTIME}  ## either "runc" if running locally on debug mode or "nvidia" on production with multi processors
        volumes:
            - ${ML_FILE_PATH}:/host
        depends_on:
            - rabbitmq
            - app
        environment:
            LC_ALL: "C.UTF-8"
            LANG: "C.UTF-8"
            MPLCONFIGDIR: /host/tmp
        volumes:
            - ${ML_FILE_PATH}:/host
    celery-beat:
        image: ${ML_IMAGE_NAME}
        entrypoint: "celery --broker='amqp://<user>:<password>@rabbitmq:5672//' -A taskqueue.celeryapp beat --uid 1111"
        runtime: ${RUNTIME}  ## either "runc" if running locally on debug mode or "nvidia" on production with multi processors
        depends_on:
            - rabbitmq
            - app
        environment:
            LC_ALL: "C.UTF-8"
            LANG: "C.UTF-8"
            MPLCONFIGDIR: /host/tmp
        volumes:
            - ${ML_FILE_PATH}:/host
    app:
        build: .
        entrypoint: ${ML_ENTRYPOINT}  # just starts a flask app
        image: ${ML_IMAGE_NAME}
        ports:
            - "3000:3000"
        expose:
            - "3000"
        volumes:
            - ${ML_FILE_PATH}:/host
        restart: always
        runtime: ${RUNTIME}
        healthcheck:
            test: ["CMD", "curl", "http:/localhost:3000/?requestType=health-check"]
            start_period: 30s
            interval: 30s
            timeout: 5s
        environment:
            SCHEDULER: "off"
            TZ: "UTC"
            LC_ALL: "C.UTF-8"
            LANG: "C.UTF-8"

我可以按预期从容器内访问服务。

我不确定我错过了什么。非常感谢您的帮助!

【问题讨论】:

    标签: docker docker-compose


    【解决方案1】:

    我不确定,但我认为您不能将流量从主机路由到 mac osx 上的容器。

    https://docs.docker.com/desktop/mac/networking/

    【讨论】:

    • 是的!我正在使用该端口映射逻辑,因此我希望能够在主机(我的计算机)上 curl localhost:3000 并点击我的应用程序。但没有运气。
    • 您能否将您的应用映射到端口 80:3000 进行测试?
    • 是的,刚刚改了,还是什么都没有
    • 你在做什么? curl -i http://172.x.x.x: 3000?
    • 来自主机:curl --location --request GET 'http://localhost:3000/test' --> 失败,来自外部主机:curl --location --request GET 'http://&lt;host-ip&gt;:3000/test' --> 也失败,来自容器内部curl --location --request GET 'http://localhost:3000/test' --> 按预期返回
    【解决方案2】:

    这最终与 docker-compose 无关。

    我的烧瓶应用程序在 127.0.0.1 上启动。我需要把它作为一个 externally visible server.

    我只需将 --host=0.0.0.0 添加到我的启动脚本中。

    【讨论】:

    • 我怀疑是配置问题。如果现在能用就好了:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    • 1970-01-01
    • 2017-04-05
    • 2017-06-02
    • 2020-08-14
    • 2016-11-18
    • 1970-01-01
    相关资源
    最近更新 更多