系统环境: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
[[email protected] ~]# yum -y install docker-engine [[email protected] ~]# systemctl start docker [[email protected] ~]# systemctl enable docker
2. 安装制作CentOS镜像的工具
[[email protected] ~]# yum -y install febootstrap
ps: CentOS7中的yum源没有febootstrap包,可以在CentOS6中使用 "yumdownloader febootstrap"命令将febootstrap下载到本地,之后放在7上进行安装
3. 制作CentOS镜像文件centos6-image目录
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
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 700 /root/.ssh EXPOSE 22 RUN echo ‘root:123.com‘ | chpasswd ENV LANG en_US.UTF-8 ENV LC_ALL en_US.UTF-8 CMD /usr/sbin/sshd -D #End
Dockerfile
[[email protected] ~]# docker build -t centos6-ssh .
2. 创建容器
[[email protected] ~]# docker run -itd -p 33301:22 centos6-ssh
3. ssh登陆容器
[[email protected] ~]# ssh [email protected]127.0.0.1 -p 33301
时间: 2024-10-11 21:17:06