我想启动sshd iside Docker并执行一些ssh命令以构建映像。这是我的Dockerfile:
if(filter_has_var(INPUT_POST, 'data')){
$email = trim($_POST['data']);
$sanitized = filter_var($email, FILTER_SANITIZE_EMAIL);
if($email === $sanitized && filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "This is a valid email: " . $email;
} else {
echo "This is an invalid email: " . $email;
}
}
在这里我得到了错误:
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
ssh 127.0.0.1返回:
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
与ping和wget相似的行为。容器/ etc / hosts文件:
ssh: connect to host 127.0.0.1 port 22: Connection refused
这里有什么想法吗?
答案 0 :(得分:0)
发现dockerfile RUN命令现在允许使用“&”,因此sshd后台进程不会启动。我创建.sh脚本并从中运行/ usr / sbin / sshd -D和。