一、下载:
https://www.huaweicloud.com/content/cloudbu-develop/china/zh-cn/developer/euleros/download.html?developlan=Other
https://developer.huawei.com/ict/site-euleros/euleros/repo/yum
二、华为镜像云:
https://mirrors.huaweicloud.com/euler/2.3/os/x86_64/iso/20180630/
https://developer.huawei.com/ict/site-euleros/euleros/repo/yum/2.5/os/x86_64/Packages/
三、制作镜像:
https://github.com/euleros/euleros-docker-images
挂载iso镜像执行
sudo su -
mount -t iso9660 -o loop /home/my/Downloads/EulerOS-V2.0SP5-x86_64-dvd.iso /mnt/iso
mkdir images_scripts && cd images_scripts
unzip euleros-docker-images-master.zip
cd euleros-docker-images-master/scripts
export OS_VERSION=2.5
export ISO_PATH=/mnt/iso
export RPM_ROOT=$(pwd)/rootfs
bash generate.sh
split -b 9m -d EulerOS-2.5-x86_64.tar.xz EulerOS-2.5-x86_64.tar.xz.
cat EulerOS-2.5-x86_64.tar.xz.* > EulerOS-2.5-x86_64.tar.xz
cd x86_64
cat EulerOS-2.5-x86_64.tar.xz |docker import - euleros:2.0.5
docker run -it euleros:2.0.5 /bin/bash
docker save euleros:2.0.5 -o euleros_2.0.5.tar
docker load -i euleros_2.0.5.tar
附件:
generate.sh
machine=$(uname -m)
if [ -z $RPM_ROOT ]; then
rm -rf $machine
echo "please set PRM_ROOT"
exit
fi
if [ "x$RPM_ROOT" != "x$(pwd)/rootfs" ]; then
echo "should set PRM_ROOT to $(pwd)/rootfs"
exit
fi
if [ -z "$OS_VERSION" ]; then
echo "should set OS_VERSION"
exit
fi
if [ -z $ISO_PATH ];then
echo "please set ISO_PATH as iso mountpoint"
exit
fi
if [ "x$USER" != "xroot" ]; then
echo "please run as root"
exit
fi
if [ -e $RPM_ROOT ];then
echo "rootfs exist, remove it"
rm -rf $RPM_ROOT
fi
mkdir -p ${RPM_ROOT}
# init rpmdb
rpm --root ${RPM_ROOT} --initdb
# init yum repo
mkdir -p ${RPM_ROOT}/etc/yum.repos.d
euleros_repo=${RPM_ROOT}/etc/yum.repos.d/euleros.repo
echo "[base]" > ${euleros_repo}
echo name=EulerOS-2.0SP3 base >> ${euleros_repo}
echo baseurl=file://${ISO_PATH} >> ${euleros_repo}
echo "enabled=1" >> ${euleros_repo}
# install rpm key
rpm --root ${RPM_ROOT} --import $ISO_PATH/RPM-GPG-KEY-EulerOS
# install package
echo "install package.."
yum -y --installroot=${RPM_ROOT} install yum
yum -y --installroot=${RPM_ROOT} clean all
pwd
cp ./clean_in_chroot.sh ${RPM_ROOT}/
# clean up
chroot $RPM_ROOT /clean_in_chroot.sh
echo "return: $?"
#if [ $? -ne 0 ]; then
# echo "chroot failed"
# echo
#
#fi
rm ${RPM_ROOT}/clean_in_chroot.sh
echo "generate packages"
rm -rf $machine
mkdir $machine
echo "generate $machine/EulerOS-$OS_VERSION-${machine}.tar.xz"
tar -C $RPM_ROOT -cJf $machine/EulerOS-$OS_VERSION-${machine}.tar.xz .
echo "enerate $machine/EulerOS-$OS_VERSION-${machine}-tar-xz.sha256"
sha256sum $machine/EulerOS-$OS_VERSION-${machine}.tar.xz > $machine/EulerOS-$OS_VERSION-${machine}-tar-xz.sha256
clean_in_chroot.sh
#!/bin/bash
rm /var/cache/yum/* -rf
rm /var/cache/yum/.* -rf
rm /var/lib/yum/yumdb/* -rf
rm /var/lib/yum/history/* -rf
rm /root/.rpmdb -rf
# set up yum.repo
echo "[base]" > /etc/yum.repos.d/euleros.repo
echo "name=EulerOS-2.0SP5 base" >>/etc/yum.repos.d/euleros.repo
echo "baseurl=http://mirrors.huaweicloud.com/euler/2.5/os/x86_64/" >>/etc/yum.repos.d/euleros.repo
echo "enabled=1" >> /etc/yum.repos.d/euleros.repo
echo "gpgcheck=1" >> /etc/yum.repos.d/euleros.repo
echo "gpgkey=http://mirrors.huaweicloud.com/euler/2.5/os/RPM-GPG-KEY-EulerOS" >> /etc/yum.repos.d/euleros.repo
cd /usr/share/locale
shopt -s extglob
rm -rf !(zh_CN | en_US)
localedef --list-archive | grep -v -i ^en_US.utf8 | xargs localedef --delete-from-archive
mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.tmpl
build-locale-archive
truncate -s 0 /usr/lib/locale/locale-archive.tmpl
echo "clean in container success"
四、OTHER:
1、最小化安装:EulerOS-V2.0SP5-x86_64
2、备份成tar
tar --numeric-owner --exclude=/proc --exclude=/sys --exclude=/dev --exclude=/run \
--exclude=/etc/systemd \
--directory=/ -cvpf /tmp/euleros_v2.0sp5.tar /
3、导入:
cat /tmp/euleros_v2.0sp5_docker.tar.gz | docker import - euleros:2.0.sp5.1
docker run -it euleros:2.0.sp5.1 /bin/bash
4、精简:
5、下载标准镜像
docker pull euleros
docker run -it euleros /bin/bash
6、查看信息:
bash-4.2# cat /etc/*release*
EulerOS release 2.0 (SP3)
EulerOS release 2.0 (SP3)
NAME="EulerOS"
VERSION="2.0 (SP3)"
ID="euleros"
ID_LIKE="rhel fedora centos"
VERSION_ID="2.0"
PRETTY_NAME="EulerOS 2.0 (SP3)"
ANSI_COLOR="0;31"
EulerOS release 2.0 (SP3)
EulerOS release 2.0 (SP3)
cpe:/o:euler:euleros:2.0SP3:ga:server
bash-4.2# yum list installed
bash-4.2# rpm -qa
7、建立repo:
mv /etc/yum.repos.d/EulerOS.repo /etc/yum.repos.d/EulerOS.repo.bak
echo "[base]">/etc/yum.repos.d/EulerOS.repo
echo "name=EulerOS-2.0SP5 base">>/etc/yum.repos.d/EulerOS.repo
echo "baseurl=http://mirrors.huaweicloud.com/euler/2.5/os/x86_64/">>/etc/yum.repos.d/EulerOS.repo
echo "enabled=1">>/etc/yum.repos.d/EulerOS.repo
echo "gpgcheck=1">>/etc/yum.repos.d/EulerOS.repo
echo "gpgkey=http://mirrors.huaweicloud.com/euler/2.5/os/RPM-GPG-KEY-EulerOS">>/etc/yum.repos.d/EulerOS.repo
yum clean all
yum makecache
rpm -rebuilddb
yum list installed
rpm -qa
8、整理:
Dockerfile
FROM scratch
LABEL maintainer="mbzhong"
COPY --from=euleros:2.0.sp5.1 /etc /etc
COPY --from=euleros:2.0.sp5.1 /home /home
COPY --from=euleros:2.0.sp5.1 /opt /opt
COPY --from=euleros:2.0.sp5.1 /root /root
COPY --from=euleros:2.0.sp5.1 /usr /usr
COPY --from=euleros:2.0.sp5.1 /var /var
COPY --from=euleros:2.0.sp5.1 /tmp /tmp
RUN systemctl disable firewalld.service && \
yum -y remove bind-libs bind-libs-lite dhclient dhcp-common dhcp-libs dracut-network && \
yum -y remove e2fsprogs e2fsprogs-libs ebtables ethtool file firewalld freetype gettext gettext-libs && \
yum -y remove groff-base
# RUN yum -y remove grub2 grub2-tools
# RUN yum -y remove grubby
RUN yum -y remove initscripts iproute iptables kexec-tools && \
yum -y remove libcroco libgomp libmnl libnetfilter_conntrack libnfnetlink libselinux-python lzo && \
yum -y remove libunistring os-prober python-decorator python-slip python-slip-dbus snappy && \
yum -y remove sysvinit-tools which linux-firmware GeoIP firewalld-filesystem qemu-guest-agent && \
yum -y remove iwl* *firmware* --exclude=kernel-firmware && \
yum -y remove yum -y remove NetworkManager* OpenIPMI* perl*
# RUN rpm -e kernel
RUN mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.back && \
localedef -f UTF-8 -i zh_CN zh_CN.UTF8 && \
localedef --list-archive && \
rm -f /usr/lib/locale/locale-archive.back && \
yum clean all && \
rm -rf /boot && \
rm -rf /etc/firewalld && \
rm -rf /var/cache/yum/x86_64 && \
rm -f /tmp/ks-script* && \
rm -rf /etc/sysconfig/network-scripts/ifcfg-* && \
rm -rf /etc/udev/hwdb.bin && \
rm -rf /usr/lib/udev/hwdb.d/* && \
rm /var/run/nologin
RUN rm -fr /proc && \
rm -fr /sys && \
rm -fr /mnt && \
rm -fr /var/cache && \
rm -fr /usr/share/{foomatic,backgrounds,perl5,fonts,cups,qt4,groff,kde4,icons,pixmaps,emacs,gnome-background-properties,sounds,gnome,games,desktop-directories} && \
rm -fr /var/log && \
rm -fr /etc/selinux/targeted && \
rm -fr /run && \
rm -fr /usr/lib/firmware && \
rm -fr /usr/lib/grub && \
rm -fr /usr/lib/kbd && \
rm -fr /usr/lib64/NetworkManager && \
rm -fr /usr/lib64/libasound.so.2.0.0 && \
rm -fr /usr/lib64/libmozjs-17.0.so && \
rm -fr /usr/lib64/libnm.so.0.1.0 && \
rm -fr /usr/lib64/libslang.so.2.2.4 && \
rm -fr /usr/lib64/xtables && \
rm -fr /usr/libexec/nm-iface-helper && \
rm -fr /usr/libexec/postfix && \
rm -fr /usr/sbin/NetworkManager && \
rm -fr /usr/sbin/eapol_test && \
rm -fr /usr/share/alsa && \
rm -fr /usr/share/backgrounds/* && \
rm -fr /usr/share/doc && \
rm -fr /usr/share/hwdata && \
rm -fr /usr/share/info/*.gz && \
rm -fr /usr/share/kde4 && \
rm -fr /usr/share/man && \
rm -fr /usr/share/locale/* && \
rm -fr /var/cache/yum
RUN rpm -rebuilddb
[root@b3514c5917df yum.repos.d]# cat /etc/*release*
EulerOS release 2.0 (SP5)
EulerOS release 2.0 (SP5)
NAME="EulerOS"
VERSION="2.0 (SP5)"
ID="euleros"
ID_LIKE="rhel fedora centos"
VERSION_ID="2.0"
PRETTY_NAME="EulerOS 2.0 (SP5)"
ANSI_COLOR="0;31"
EulerOS release 2.0 (SP5)
EulerOS release 2.0 (SP5)
cpe:/o:euler:euleros:2.0SP5:ga:server
/etc/grub.d/10_linux.rpmsave
ls /etc/systemd/system/multi-user.target.wants/ |awk '{print "systemctl disable "$1}'|sh
systemctl disable firewalld.service
rpm -e kernel
yum -y remove bind-libs bind-libs-lite dhclient dhcp-common dhcp-libs dracut-network
yum -y remove e2fsprogs e2fsprogs-libs ebtables ethtool file firewalld freetype gettext gettext-libs
yum -y remove groff-base grub2 grub2-tools grubby initscripts iproute iptables kexec-tools
yum -y remove libcroco libgomp libmnl libnetfilter_conntrack libnfnetlink libselinux-python lzo
yum -y remove libunistring os-prober python-decorator python-slip python-slip-dbus snappy
yum -y remove sysvinit-tools which linux-firmware GeoIP firewalld-filesystem qemu-guest-agent
yum -y remove iwl* *firmware* --exclude=kernel-firmware
yum -y remove yum -y remove NetworkManager* OpenIPMI* perl*
yum list installed |grep -v yum|grep -v bash|grep x86_64 |sort| awk '{print "yum -y remove "$1}'|sh
rpm -qa|sort |grep -v sh|grep -v yum|grep -v lib|grep -v grep|grep -v awk|grep -v rpm|awk '{print "rpm -e "$1}'|sh
rpm -qa|sort |grep -v bash|grep -v yum|grep -v libbz2|awk '{print "rpm -e --nodeps "$1}'|sh
9、清理临时文件夹:
yum clean all
yum clean allrm -rf /var/cache/yum
rm -rf /boot
rm -rf /etc/firewalld
rm -rf /var/cache/yum/x86_64
rm -f /tmp/ks-script*
rm -rf /etc/sysconfig/network-scripts/ifcfg-*
rm -rf /etc/udev/hwdb.bin
rm -rf /usr/lib/udev/hwdb.d/*
rm /var/run/nologin
yum install -y net-tools
umount /run
10、语言包:
mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.back
localedef -f UTF-8 -i zh_CN zh_CN.UTF8
localedef --list-archive
rm -f /usr/lib/locale/locale-archive.back
11、重建
rpm -rebuilddb
12、打包:
ar –numeric-owner –exclude=/boot –exclude=/proc –exclude=/sys -cvf centos7.6-docker.tar /
tar –numeric-owner –exclude=/boot \
–exclude=/etc/selinux/targeted \
–exclude=/proc \
–exclude=/run \
–exclude=/sys \
–exclude=/usr/lib/firmware \
–exclude=/usr/lib/grub \
–exclude=/usr/lib/kbd \
–exclude=/usr/lib64/NetworkManager \
–exclude=/usr/lib64/libasound.so.2.0.0 \
–exclude=/usr/lib64/libmozjs-17.0.so \
–exclude=/usr/lib64/libnm.so.0.1.0 \
–exclude=/usr/lib64/libslang.so.2.2.4 \
–exclude=/usr/lib64/xtables \
–exclude=/usr/libexec/nm-iface-helper \
–exclude=/usr/libexec/postfix \
–exclude=/usr/sbin/NetworkManager \
–exclude=/usr/sbin/eapol_test \
–exclude=/usr/share/alsa \
–exclude=/usr/share/backgrounds/* \
–exclude=/usr/share/doc \
–exclude=/usr/share/hwdata \
–exclude=/usr/share/info/*.gz \
–exclude=/usr/share/kde4 \
–exclude=/usr/share/man \
–exclude=/usr/share/locale/* \
–exclude=/var/cache/yum \
-cvf centos7.6-docker.tar /
13、测试:
Step-1 卸载不必要的软件包
为了缩小文件系统的体积,需要删除一些不必要的软件包。在Shell中执行以下命令:
CentOS 6.9系统(虚拟机-1):
yum remove -y iwl* ql* xorg* ipw* *firmware* --exclude=kernel-firmware
CentOS 7.4.1708系统(虚拟机-2):
yum remove -y iwl* *firmware* --exclude=kernel-firmware
Step-2 清除yum缓存
清除yum缓存,进一步缩小文件系统的体积。在Shell中执行以下命令:
yum clean all
yum clean allrm -rf /var/cache/yum
Step-3 打包文件系统
将文件系统打包,排除所有运行时才创建的目录,以及不必要的目录。在Shell中执行以下命令:
tar --numeric-owner --exclude=/proc --exclude=/sys --exclude=/mnt --exclude=/var/cache --exclude=/usr/share/{foomatic,backgrounds,perl5,fonts,cups,qt4,groff,kde4,icons,pixmaps,emacs,gnome-background-properties,sounds,gnome,games,desktop-directories} --exclude=/var/log -zcvf /mnt/CentOS-6.9-BaseImage.tar.gz /
tar --numeric-owner --exclude=/proc --exclude=/sys --exclude=/mnt --exclude=/var/cache --exclude=/usr/share/{foomatic,backgrounds,perl5,fonts,cups,qt4,groff,kde4,icons,pixmaps,emacs,gnome-background-properties,sounds,gnome,games,desktop-directories} --exclude=/var/log -zcvf /mnt/CentOS-7.4-BaseImage.tar.gz /
Step-4 安装和启动Docker
安装CentOS的EPEL源和REMI源,然后安装Docker软件包,最后启动Docker服务。在Shell中运行一下命令:
# 安装EPEL源和REMI源rpm -Uvh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-6.rpm# 安装Docker软件包yum install -y docker-io# 启动Docker服务service docker start
# 安装EPEL源和REMI源rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpmrpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm# 安装Docker软件包yum install -y docker-io# 启动Docker服务systemctl start docker.service
Step-5 导入镜像仓库
将打包的文件系统,导入Docker的本地镜像仓库。在Shell中运行以下命令:
cat /mnt/CentOS-6.9-BaseImage.tar.gz | docker import - centos-tar:6.9
cat /mnt/CentOS-7.4-BaseImage.tar.gz | docker import - centos-tar:7.4.1708
Step-6 验证
检查Docker的本地镜像仓库,若如下图所示,则表明镜像创建成功:
通过tar打包创建的CentOS 6.9基础镜像
通过tar打包创建的CentOS 7.4基础镜像
运行一个示例容器,在控制台中输出提示信息,如下图所示:
通过tar打包创建的CentOS 6.9基础镜像的运行示例
通过tar打包创建的CentOS 7.4基础镜像的运行示例
使用:
git clone https://github.com/jpetazzo/pipework
cp pipework/pipework /usr/local/bin/
chmod +x /usr/local/bin/pipework
vim /etc/sysconfig/network-scripts/ifcfg-em1
vim /etc/sysconfig/network-scripts/ifcfg-br0
systemctl restart network
docker images
docker run -it --name centos6.8 --net=none b7feffaa0bdc /bin/bash
docker ps -a
docker start fc017c4eb893
pipework br0 fc017c4eb893 192.168.10.48/[email protected]
docker exec fc017c4eb893 ip add
docker exec -it fc017c4eb893 /bin/bash
docker ps -a
docker run -h datanode7 -e TZ='Asia/Shanghai' --storage-opt size=1024G --name centos6.8 -it --net=none fcca04213152 /bin/bash
docker start 1d45a29e2b81
pipework br0 centos6.8 192.168.10.45/[email protected]
docker exec centos6.8 ip add
docker exec -it centos6.8 /bin/bash
docker ps -a
参考资料:
https://github.com/euleros/euleros-docker-images
https://www.lizenghai.com/archives/5230.html
https://blog.csdn.net/chengrowe/article/details/81536545