我已经构建了一个 docker 镜像,其中包含一个带有 MQTT 和 Mongodb 模块的 C++ 应用程序。当我尝试使用 Cloud Foundry 将其部署到我的云时,出现了以下错误:
ERR Failed to make TCP connection to port 1883: connection refused
鉴于 1883 是 MQTT 的监听端口。我在 CloudFoundry Docker 上找到了我唯一需要做的就是包括曝光 1883 在我已经完成的 Dockerfile 中。
谁能解释我到目前为止还没有考虑到什么?谢谢你的阅读。
最佳答案
引用 github commit 的声明.
You expose ports using the
EXPOSE
keyword in the Dockerfile or the--expose
flag todocker run
. Exposing ports is a way of documenting which ports are used, but does not actually map or open any ports. Exposing ports is optional.
如果您想在端口 1883 上访问 MQTT,请使用 -p option在您的 docker run 命令中。
在你的情况下
docker run -itd -p 1883:1883 mqtt-image-name
希望这可以帮助。
更新:
对不起我误会了,我通过了official博士。
EXPOSE
应该在你的情况下工作。你得到的错误
ERR Failed to make TCP connection to port 1883: connection refused
意味着您的应用程序或云代工厂有问题。The error might be because your app either does not become available on port 1883 due to a failure, or that it takes longer than the specified healthcheck timeout for it to be up and running, thus failing the healthcheck.
请查看this了解更多信息。
希望这可以帮助。
关于docker - 将 Docker 容器部署到 Cloud Foundry 时,MQTT 端口连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56856987/