【发布时间】: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