I want to start sshd iside Docker and perform some ssh commands in order to build image. Here is my 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
And I get error here:
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
And ssh 127.0.0.1 returns:
ssh: connect to host 127.0.0.1 port 22: Connection refused
Similar behaviour with ping and wget. Container /etc/hosts file:
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
Any ideas whats happens here?