最近在项目中需要测试运维脚本,但是在网上都找不到可以模拟阿里云的centos7镜像,所以就自己构建了一个,跟大家分享下。
构建平台:
- 操作系统 window 11
- 软件 docker desktop
工作目录:
CentOS-Base.repo
[base]
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
enabled=1
failovermethod=priority
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7
dockerfile
FROM centos:7
COPY ./config /etc/yum.repos.d/
RUN yum clean all && \
yum makecache && \
yum install -y openssh-server openssh-clients && \
echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config && \
ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa -b 4096 && \
echo "<<id_rsa.pub>>" >> /root/.ssh/authorized_keys
CMD [ "/usr/sbin/init" ]
构建方法:
在当前目录下下执行(别忘了最后还有一个.)
docker build -t centos:ali .
这个镜像是可以开启了ssh访问,可以将<<id_rsa.pub>>替换成运维服务器上的ssh-key。镜像大小约1.24G,可以根据需要安装需要的环境,如python3等。
标签:http,CentOS,centos,mirrors,centos7,aliyun,镜像,docker,com From: https://blog.csdn.net/luobobaicai3/article/details/140171838