Dockerfile方式创建镜像并启动容器
https://www.cnblogs.com/BINGJJFLY/p/12808549.html
可以添加root密码:echo root:root | chpasswd
安装配置SSH服务
yum install openssh-server openssh-clients -y vim /etc/ssh/sshd_config #HostKey /etc/ssh/ssh_host_ecdsa_key #HostKey /etc/ssh/ssh_host_ed25519_key
创建公私钥
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key ls /etc/ssh/
修改root密码
echo root:root | chpasswd
启动SSH服务
/usr/sbin/sshd -D & netstat -tunlp
Commit方式创建镜像
docker commit -m="create an sshd image" -a="bingjjfly" 容器的ID REPOSITORY:TAG
创建拥有SSH服务的容器
# 可以映射不同的端口 docker run -p 1022:22 -d SSH镜像ID
Dockerfile方式创建镜像
FROM centos:centos6.8 MAINTAINER bingjjfly<bingjjfly@docker.org> RUN yum install openssh-server openssh-clients -y RUN mkdir /var/run/sshd RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key RUN /bin/echo 'root:root'|chpasswd RUN /bin/sed -i 's/.*session.*required.*pam_loginuid.so.*/session optional pam_loginuid.so/g' /etc/pam.d/sshd RUN /bin/echo -e "LANG="en_US.UTF-8"" > /etc/default/local EXPOSE 22 CMD /usr/sbin/sshd -D docker build -f /mydocker/ssh/Dockerfile -t bingjjfly/ssh:1.0 . docker run -d -p 1022:22 --name bingjjfly_ssh_1.0 bingjjfly/ssh:1.0
SSH方式连接服务器
# 宿主机IP ssh root@192.168.88.128 -p 1022