【问题标题】:connect to localhost port inside the docker container is refused连接到 docker 容器内的 localhost 端口被拒绝
【发布时间】:2018-01-12 08:25:17
【问题描述】:

Docker 版本 17.12.0-ce,构建 c97c6d6

操作系统:Debian GNU/Linux 9(延伸)

这是我的Dockerfile

FROM ubuntu:14.04

EXPOSE 5432

构建容器:

 $ docker build -t expose_5432_port .

运行容器:

docker run -ti expose_5432_port /bin/bash

我尝试连接容器内的端口:

root@5f15a7ebd280:/# nc -v -z 127.0.0.1 5432
nc: connect to 127.0.0.1 port 5432 (tcp) failed: Connection refused

如何连接端口?

【问题讨论】:

    标签: docker


    【解决方案1】:

    这是意料之中的。

    EXPOSE 打开了一种连接到容器中端口 5432 的方法,但正如它所说的 connect to 127.0.0.1 port 5432 (tcp) failed: Connection refused,您可以成功连接/到达该端口,但由于该端口上没有任何运行,因此表示连接被拒绝。你必须让一些应用程序在端口 5432 上运行。

    参考- https://serverfault.com/questions/725262/what-causes-the-connection-refused-message

    【讨论】:

    • 确实,例如,当您启动 docker run -d postgres 这将起作用,因为 postgres 服务正在端口 5432 上运行(检查其 dockerfile)
    猜你喜欢
    • 2019-09-06
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多