Docker:“;“网络无法访问”;集装箱内
我想启动sshd-iside-Docker并执行一些ssh命令来构建映像。这是我的Dockerfile:Docker:“;“网络无法访问”;集装箱内,docker,networking,sshd,Docker,Networking,Sshd,我想启动sshd-iside-Docker并执行一些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
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
知道这里发生了什么吗?发现dockerfile运行命令现在允许“&”,因此sshd后台进程不会启动。我创建.sh脚本并从中运行/usr/sbin/sshd-D&D