【问题标题】:Docker SSH forwarding - bind: Address not availableDocker SSH 转发 - 绑定:地址不可用
【发布时间】:2019-02-27 23:29:39
【问题描述】:

我有一个 Docker 容器,我希望它能够通过 SSH 隧道与数据库进行交互。

我的 Docker 镜像是基于 alpine 镜像构建的,在 Dockerfile 中我安装了 openssh-client 并公开了 27017 端口

当我启动 Docker 映像并尝试通过以下方式转发端口时:

ssh -i /.ssh/ssh_key user@remote_ip -L 27017:localhost:27017 -Nf

我收到一个错误:

bind: Address not available

ssh 到远程服务器没有问题,但我无法转发端口。

谢谢

【问题讨论】:

    标签: docker ssh portforwarding openssh alpine


    【解决方案1】:

    我设法使用这个入口点从 docker-compose 创建了一个 ssh 隧道:

    ssh -4 -i /.ssh/ssh_key -NL *:27017:0.0.0.0:27017 user@remote_ip
    


    然后我可以通过使用 docker-compose 创建的网络从另一个容器使用 ssh 隧道

    docker run --network=tunnel_default image nmap -p 27027 service_name
    


    tunnel_default 是网络的名称

    image 是一个安装了nmap 的 docker 镜像(它允许您检查打开的端口)

    service_name 是我在 docker-compose 中给服务起的名字

    【讨论】:

    • 您的端口映射和运行选项不匹配。 27017 与 27027
    • 哦,天哪,非常感谢您,我花了 48 小时尝试通过 docker 建立隧道,这解决了我的问题。非常感谢
    【解决方案2】:

    如果您不指定要使用的接口,您可能会得到“绑定地址不可用”。默认情况下,它将使用所有这些,包括 IPV6。就我而言,它绑定在 IPV4 上,但“地址不可用”实际上是用于 IPV6,例如bind [::1]:2001: Address not available。如果您使用-4 选项,这将仅使用 IPV4,如果您收到 IPV6 类型错误,那么这将为您解决这个问题,在 Arch Linux 上对我来说也是如此。

    -4 强制 ssh 仅使用 IPv4 地址。


    -D [绑定地址:]端口

       Specifies a local “dynamic” application-level port forwarding.  This works by allocating a
        socket to listen to port on the local side, optionally bound to the specified
        bind_address.  Whenever a connection is made to this port, the connection is forwarded
        over the secure channel, and the application protocol is then used to determine where to
        connect to from the remote machine.  Currently the SOCKS4 and SOCKS5 protocols are sup‐
        ported, and ssh will act as a SOCKS server.  Only root can forward privileged ports.
        Dynamic port forwardings can also be specified in the configuration file.
    
       IPv6 addresses can be specified by enclosing the address in square brackets.  Only the
        superuser can forward privileged ports.  By default, the local port is bound in accordance
        with the GatewayPorts setting.  However, an explicit bind_address may be used to bind the
        connection to a specific address.  The bind_address of “localhost” indicates that the lis‐
        tening port be bound for local use only, while an empty address or ‘*’ indicates that the
        port should be available from all interfaces.
    

    【讨论】:

      猜你喜欢
      • 2019-08-21
      • 1970-01-01
      • 1970-01-01
      • 2016-04-10
      • 2016-10-24
      • 2021-01-02
      相关资源
      最近更新 更多