一、编辑Dockerfile
vim Dockerfile
# SSH
# Version 0.0.1
# IMAGES
FROM 192.168.0.216:5000/centos
# MAINTAINER
MAINTAINER hongxue hongxue@showjoy.com
# YUM
RUN yum -y update
RUN yum -y install vim net-tools openssh-server
# SSH
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ED25519_key
RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
RUN mkdir /var/run/sshd
RUN sed -i 's/session required pam_loginuid.so/#session required pam_loginuid.so/g' /etc/pam.d/sshd
RUN echo "root:xxxxxxx" | chpasswd
# EXPOSE
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]
二、构建镜像
docker build -t container_ssh .
三、运行镜像生成容器
[root@docker Dockerfile]# docker images | grep container_ssh
container_ssh latest 88f1388b6337 2 minutes ago 328.1 MB
[root@docker Dockerfile]# docker run -d -it -p 122:22 --name ssh container_ssh
3e5442e5b35fa72fadfc33fe52db03b645544f39b58cf164ed43f8bb799213b2
四、验证ssh登录是否成功
时间: 2024-11-05 18:46:45