1、vi Dockerfile
FROM centos:7 MAINTAINER huangat RUN yum -y update&&yum -y install passwd openssl openssh-server openssh-clients RUN mkdir -p /var/run/sshd/ RUN sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_ecdsa_key RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_ed25519_key RUN echo "123456" | passwd --stdin root ADD run.sh /run.sh RUN chmod 755 /run.sh EXPOSE 22 CMD ["/run.sh"]
2、vi run.sh
! /bin/bash
/usr/sbin/sshd -D
3、docker build
-t centos7sshd .
4、ocker run
-itd -p 10022:22 --name centos7withsshd01 centos7sshd /run.sh
5、docker run
-itd -p 10022:22 -m 500m --cpus 1 --name centos7withsshd01 centos7sshd /run.sh