Use the dockerfile Method
Preparations
# Mkdir sshd_ubuntu create a working directory
# Cd sshd_ubuntu
# Touch dockerfile run. Sh the file to be copied to the container after being created
# Vi run. Sh run. SH Content
#! /Bin/bash
/Usr/sbin/sshd-d
# Cat ~ /. Ssh/id_rsa.pub> authorized_keys copy the public key that needs to be logged on to the container Machine
Write dockerfile
------------------------------------
# Set the inherited Image
Fromubuntu: 163
# Provider Information
Maintainerfrom buranle, test sshd Images
# Because the image used has been changed to the APT source of 163, no changes will be made here.
# Install the SSH service
Runapt-Get install-y openssh-Server
Run mkdir-P/var/run/sshd
Run mkdir-P/root/. SSH
# Remove PAM module restrictions
Run sed-Ri's/session required pam_loginuid.so/# session required pam_loginuid.so/G'/etc/PAM. d/sshd
# Copy the file to the response location and grant the script execution permission
Addauthorized_keys/root/. Ssh/authorized_keys
Addrun. sh/run. Sh
Run chmod755/run. Sh
# Open Port
Expose 22
# Set self-starting commands
CMD ["/run. Sh"]
----------------------------------------------
# Dockerbuild-T sshd: dockerfile.
The success text indicates that our image has been successfully generated.
# Dockerimages
650) This. width = 650; "Title =" 2.png" style = "float: none;" alt = "wkiol1syufty5ryqaadwtmwhg8u389.jpg" src = "http://s3.51cto.com/wyfs02/M01/58/7A/wKioL1SyufTy5RYQAADWtmwHG8U389.jpg"/>
# Dockerrun-D-P 1111:22 sshd: dockerfile
650) This. width = 650; "Title =" 1.png" style = "float: none;" alt = "wkiom1syuszafs3oaagpg2ytazy130.jpg" src = "http://s3.51cto.com/wyfs02/M01/58/7D/wKiom1SyuSzAFs3OAAGPG2ytAzY130.jpg"/>
2. Of course we can also use the commit method. We will not introduce it here.
Note: The method of using apt for ease of Source
Change/etc/APT/sources. List or create a new 163. List under source. d. The content is
Deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
Deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
Deb http://mirrors.163.com/ubuntu/ trusty-Updates main restricted universe multiverse
Deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
Deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
The Deb-Src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
Deb-Src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
Deb-Src http://mirrors.163.com/ubuntu/ trusty-Updates main restricted universe multiverse
The Deb-Src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
The Deb-Src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
Create an image that provides basic sshd services