Download the official image
[Email protected] ~ $ docker Pull Ubuntu:14.04#如果官方下载较慢, the standard image can be downloaded to www.dockerpool.com[Email protected] ~ $ docker Pull dl.dockerpool.com: the/ubuntu:14.04[Email protected] ~ $ docker Tag dl.dockerpool.com: the/ubuntu:14.04Ubuntu:14.04[Email protected] ~ $ docker imagesrepository TAG IMAGE ID CREATED VIRTUAL SIZEdl.dockerpool.com: the/ubuntu14.04 1357F421be383Days ago192.7Mbubuntu14.04 1357F421be383Days ago192.7MB
Create a Dockerfile folder
[email protected] ~ $ mkdir base[email protected] ~ $ cd base[email protected] ~/base $~ $ ssh-keygen#生成访问密钥[email protected] ~/base $ cat ~/.ssh/id_rsa.pub >authorized_keys
Dockerfile content:
#设置母镜像FROM ubuntu:14.04# provides information for some authors maintainer [email protected] #下面开始运行命令, here to change the source of Ubuntu for domestic 163 source run echo "Deb http ://mirrors.163.com/ubuntu/trusty main restricted Universe Multiverse ">/etc/apt/sources.listrun echo" deb/HTTP Mirrors.163.com/ubuntu/trusty-security main restricted universe multiverse ">>/etc/apt/sources.listrun echo" Deb Http://mirrors.163.com/ubuntu/trusty-updates main restricted universe multiverse ">>/etc/apt/ Sources.listrun echo "Deb http://mirrors.163.com/ubuntu/trusty-proposed main restricted universe multiverse" >>/ Etc/apt/sources.listrun echo "Deb Http://mirrors.163.com/ubuntu/trusty-backports main restricted universe multiverse" >>/etc/apt/sources.listrun apt-get updaterun apt-get upgrade-y# install ssh and supervisorrun apt-get install-y openssh-se RVer supervisorrun mkdir-p/var/run/sshdrun mkdir-p/var/log/supervisorrun mkdir-p/root/.ssh# cancel Pam limit run Sed-ri ' s/se Ssion required pam_loginuid.so/#session required PAm_loginuid.so/g '/etc/pam.d/sshd# Copy the configuration file to the appropriate location copy Supervisord.conf/etc/supervisor/conf.d/supervisord.confcopy authorized_keys/root/.ssh/authorized_keys# Open port Expose 22CMD ["/usr/bin/supervisord"]
To create a supervisor.conf file:
[email protected] ~/base $ vi supervisord.conf#文件内容如下[supervisord]nodaemon=true[program:sshd]command=/usr/sbin/sshd -D
Verify the contents of the folder
[email protected] ~/base $ lsDockerfile authorized_keys supervisord.conf[email protected] ~/base $ pwd/home/core/base
Create an image method
[email protected] ~/base $ docker build -t base/163 .
Start Container command
[email protected] ~/base $ docker run -p 100:22 -d base/163
Using a key to log in to a container
[email protected] ~/base $ ssh [email protected]127.0 . 0.1 -P 100
CoreOS Create an Ubuntu base image using a key login