构建阿里云的centos7-docker镜像

最近在项目中需要测试运维脚本,但是在网上都找不到可以模拟阿里云的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等。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值