系统环境:CentOS 7.3
将yum源切换到阿里源
可以直接写成一个脚本
#!/bin/sh
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
1. 安装Docker
[root@localhost ~]# yum -y install docker-engine
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
2. 安装制作CentOS镜像的工具
[root@localhost ~]# yum -y install febootstrap
ps: CentOS7中的yum源没有febootstrap包,可以在CentOS6中使用 "yumdownloader febootstrap"命令将febootstrap下载到本地,之后放在7上进行安装
3. 制作CentOS镜像文件centos6-image目录
[root@localhost ~]# febootstrap -i bash -i wget -i yum -i iputils -i iproute -i man -i vim-minimal -i openssh-server -i openssh-clients centos6 centos6-image http://mirrors.aliyun.com/centos/6/os/x86_64/
PS:-i 安装package, centos6 操作系统版本,centos6-doc安装目录,最后是源地址
4. 制作Docker镜像,镜像名字是centos6-base
[root@localhost ~]# cd centos6-image && tar -c .|docker import - centos6-base
制作可以ssh登陆的Docker镜像,名字是centos6-ssh
1.创建一个Dockerfile文件
#Dockerfile
FROM centos6-base
RUN ssh-keygen -q -N "" -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -q -N "" -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN sed -ri 's/session required pam_loginuid.so/#session required pam_loginuid.so/g' /etc/pam.d/sshd
RUN mkdir -p /root/.ssh && chown root.root /root && chmod /root/.ssh
EXPOSE
RUN echo 'root:123.com' | chpasswd
ENV LANG en_US.UTF-
ENV LC_ALL en_US.UTF-
CMD /usr/sbin/sshd -D
#End
Dockerfile
[root@localhost ~]# docker build -t centos6-ssh .
2. 创建容器
[root@localhost ~]# docker run -itd -p : centos6-ssh
3. ssh登陆容器
[root@localhost ~]# ssh root@127.0.0.1 -p