docker 运行container时使用--net=host,如何连到container

szqh97 szqh97 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Docker 在启动Container 时如果用了--net=host参数,要如何连到Container内部?
在默认使用bridge网络模式时可以在Dockerfile 中添加
  CMD /usr/sbin/sshd && start-app.sh 
,
这样就可以在Container启动时把sshd启动,就可以远程到container了。
但是在host网络模式下,好像是行不通啊,看到有人说用 exec,我试了下

root@debian:/home/docker/videotracker-docker-debian7_32bit/kafka# docker exec 5684aa299c11 /usr/sbin/sshd -p 3333
root@debian:/home/docker/videotracker-docker-debian7_32bit/kafka# ps -ef|grep sshd
root 463 1 0 May07 ? 00:00:00 /usr/sbin/sshd
root 637 463 0 May07 ? 00:00:03 sshd: root@pts/2
root 1849 463 0 May07 ? 00:00:03 sshd: root@pts/5
root 22733 463 0 May08 ? 00:00:00 sshd: root@pts/7
root 22770 1 0 09:56 ? 00:00:00 /usr/sbin/sshd -p 3333
root 22772 15033 0 09:56 pts/8 00:00:00 grep sshd
root 27019 1 0 May07 ? 00:00:03 sshd: root@pts/0
root 27033 597 0 May08 ? 00:00:00 /bin/sh -c /usr/sbin/sshd && start-zk.sh
root 29101 597 0 May08 ? 00:00:00 /bin/sh -c /usr/sbin/sshd && /usr/bin/start-kafka.sh

感觉好奇怪的,sshd没有在container运行,而是在hostos上运行了。
有什么好的方法吗?
...全文
评论 3
收藏 已收藏
分享
返回顶部
szqh97
Docker 1,185 成员 925 内容