Centos:
mkdir Centos-ssh
Vim Centos-ssh/dockerfile
From CentOS
Maintainer blog.rootr.cn [email protected]
RUN Yum install-y openssh-server
RUN mkdir/var/run/sshd
RUN ssh-keygen-q-T rsa-b 2048-f/etc/ssh/ssh_host_rsa_key-n "&& \
Ssh-keygen-q-T ecdsa-f/etc/ssh/ssh_host_ecdsa_key-n "&& \
Ssh-keygen-t dsa-f/etc/ssh/ssh_host_ed25519_key-n "
RUN echo "root:1234" | chpasswd
entrypoint ["/usr/sbin/sshd", "-D"]
EXPOSE 22
Docker Build-t centos:ssh/root/centos-ssh/
Docker run-d-P 2222:22 centos:ssh
SSH [email protected]-P 2222
Is you sure want to continue connecting (yes/no)? Yes
[email protected] ' s password:1234
[Email protected] ~]#
Ubuntu:
mkdir Ubuntu-ssh
Vim Ubuntu-ssh/dockerfile
From Ubuntu
Maintainer blog.rootr.cn [email protected]
RUN Apt-get update-y
RUN Apt-get install-y Openssh-server
RUN mkdir/var/run/sshd
RUN echo "root:1234" | chpasswd
#允许root用户以任何认证方式登陆 (User password authentication and public key authentication)
RUN sed-i ' s/prohibit-password/yes/g '/etc/ssh/sshd_config
entrypoint ["/usr/sbin/sshd", "-D"]
EXPOSE 22
Docker Build-t ubuntu:ssh/root/ubuntu-ssh/
Docker run-d-P 2223:22 ubuntu:ssh
SSH [email protected]-P 2223
Is you sure want to continue connecting (yes/no)? Yes
[email protected] ' s password:1234
[Email protected]:~#
Create a docker image (CentOS, Ubuntu) that supports SSH services via Dockerfile