Docker:SSH 进入共享其他容器网络空间的 sidecar

问题描述

目前我有一个容器(即:main)为一些关键应用程序提供服务,并附加了一个 sidecar 容器来使用主容器的 pid 和网络空间调试主容器。类似于以下内容:

docker run --name main -v container/logs:/logs -p 8443:443 -d main_container:latest
docker run --pid=container:main --net=container:main -d alpine_sidecar:latest

现在我计划向 sidecar 容器添加 SSH 访问权限,为此,我遵循了以下选项,但没有一个对我有利。

  1. 暴露 SSH 端口
# docker run -p 4422:22 --pid=container:main --net=container:main -d alpine_sidecar:latest
docker: Error response from daemon: conflicting options: port publishing and the container type network mode.
  1. 添加其他网络
docker network connect <network-name> <container-id>
Error response from daemon: container sharing network namespace with another container or host cannot be connected to any other network
  1. IPtables(放弃了,因为它需要容器 ip 进行转发)
iptables -t nat -A  DOCKER -p tcp --dport 4422 -j DNAT --to-destination <container-ip>:22

有没有办法实现SSH进入sidecar。感谢您的时间和帮助!谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)