对于手动制作docker镜像,尤其是在像龙芯、申威、这样的国产化的架构下,制作一款合适的基础镜像都是非常困难的,工作中,我总结了一下我制作centos下的基础镜像的过程,制作了脚本如下:

script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Basic System
yum -y --nogpgcheck --disablerepo=\* --enablerepo=base --releasever=7 --installroot=/root/CentOS-MGNT/ install systemd passwd centos-release yum openssh-server openssh-clients vim-minimal
# Mgnt Deps
yum -y --nogpgcheck --disablerepo=\* --enablerepo=base --releasever=7 --installroot=/root/CentOS-MGNT/ install procmail openssl bc groff-base libaio logrotate systemd-sysv centos-logos libedit
# Tools

yum -y --nogpgcheck --disablerepo=\* --enablerepo=base --releasever=7 --installroot=/root/CentOS-MGNT/ install lsof iproute iputils net-tools

# Change Root Password
chroot CentOS-MGNT sed -i 's#root:\*:17834#root:$6$SOdtkyhRQEc7415M$izayMJ0GeZshZzoG5P5/WVfQKDCIc4WDZWEQBBDBki/nv0DMbNG6pne3bopc6ZZH/VLsHwIFJwtGFHQBDlBdX1:#g' /etc/shadow
chroot CentOS-MGNT sed -i 's#root:\*:17834#root:$6$SOdtkyhRQEc7415M$izayMJ0GeZshZzoG5P5/WVfQKDCIc4WDZWEQBBDBki/nv0DMbNG6pne3bopc6ZZH/VLsHwIFJwtGFHQBDlBdX1:#g' /etc/shadow-

# Change SSH Port
chroot CentOS-MGNT sed -i 's/#Port .*/Port 2222/' /etc/ssh/sshd_config
# Speed UP SSH Connect
chroot CentOS-MGNT sed -i 's/#UseDNS .*/UseDNS no/' /etc/ssh/sshd_config
chroot CentOS-MGNT sed -i 's/^#PermitRootLogin.*$/PermitRootLogin yes/' /etc/ssh/sshd_config

# Package
tar --numeric-owner -cJpf CentOS-MGNT.tar.xz CentOS-MGNT

希望能够帮到有需要的朋友。谢谢!