【问题标题】:Docker: "Network is unreachable" inside containerDocker:容器内的“网络无法访问”
【发布时间】:2018-12-09 11:19:36
【问题描述】:

我想在 Docker 旁边启动 sshd 并执行一些 ssh 命令以构建映像。这是我的 Dockerfile:

FROM centos:7

RUN yum install -y which tar more util-linux-ng passwd openssh-clients openssh-server net-tools iproute; yum clean all

RUN mkdir /var/run/sshd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

RUN /usr/sbin/sshd -D &

RUN ssh localhost echo Hello

我在这里得到错误:

Step 13/13 : RUN ssh localhost echo Hello
 ---> Running in e40f2e1cc39e
ssh: connect to host localhost port 22: Network is unreachable
The command '/bin/sh -c ssh localhost echo Hello' returned a non-zero code: 255

然后 ssh 127.0.0.1 返回:

ssh: connect to host 127.0.0.1 port 22: Connection refused

ping 和 wget 的行为类似。容器 /etc/hosts 文件:

127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2      0762a183aaa3

有什么想法吗?

【问题讨论】:

    标签: docker networking sshd


    【解决方案1】:

    发现 dockerfile RUN 命令现在允许“&”,因此 sshd 后台进程不会启动。我创建 .sh 脚本并从中运行 /usr/sbin/sshd -D &。

    【讨论】:

      猜你喜欢
      • 2020-06-06
      • 2017-11-08
      • 2018-02-17
      • 2023-03-03
      • 1970-01-01
      • 2016-11-12
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多