1. Create related catalogue
[[Email protected]~]# mkdir/docker/sshd–p
2. Write Dockerfile
[Email protected]]# vim Dockerfile
# This is a dockerfile
# Version 1
# by Kevin
# Base Image
From CentOS
# maintainer
Maintainer Kevin kevinhao.blog.51cto.com
# Commands
# Install and Configure sshd
RUN Yum Install-yopenssh-server
RUN sed-i ' s/usepam yes/usepam no/g '/etc/ssh/sshd_config
# ADD The user Kevin and set it ' s password for Kevin
RUN useradd Kevin
RUN echo "Kevin:kevin" |chpasswd
RUN echo "Kevin All= (All) all" >>/etc/sudoers
# Generate a KeyPair
RUN ssh-keygen-tdsa-f/etc/ssh/ssh_host_dsa_key
RUN ssh-keygen-trsa-f/etc/ssh/ssh_host_rsa_key
#Star the SSHD service and expose the port 22
RUN mkdir/var/run/sshd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
[[Email protected]]# CD]
3. Create image
[Email protected]~]# Docker build-t kevin/sshd/docker/sshd/
4. View image
[Email protected]~]# Docker Images|grep sshd
KEVIN/SSHD latest d0b5016b8463 7 minutes ago 259.1 MB
5. Start test
[Email protected]~]# Docker run--name sshdtest-d-P kevin/sshd
6. SSH Remote
6.1. View Port Mappings
[[Email protected]~]# Docker PS
container id image command CREATED status ports NAMES
DA430C0D9F1B kevin/sshd "/usr/sbin/sshd-d" seconds ago up Notoginseng seconds 0.0.0.0:32769->22/tcp s Shdtest
6.2 Telnet using SSH
[Email protected]~]# ssh [email protected]-p32769
The authenticity of host ' [192.168.56.3]:32769 ([192.168.56.3]:32769) ' can ' t be established.
RSA key Fingerprintis d4:52:73:db:4c:85:ff:d5:6a:78:23:ff:52:67:01:2f.
Is you sure want to continue connecting (yes/no)? Yes
Warning:permanently added ' [192.168.56.3]:32769 ' (RSA) to the list of known hosts.
[Email protected] ' Spassword:
[Email protected]da430c0d9f1b~]$ pwd
/home/kevin
Success SSH Remote to Container
[Email protected]~]$ exit
Logout
Connection to192.168.56.3 closed.
You can also use SSH [email protected]<container_ip>
Linux OPS Development Group: 298324302
Beijing Linux operation and maintenance recruitment group: 153677549
This article is from the "Night Passers-by" blog, please be sure to keep this source http://kevinhao.blog.51cto.com/5204735/1732782
Using Dockerfile to create an SSH remote-enabled mirror