1、简介
Supermin 是一个用来创建迷你虚拟环境的工具,有点类似创建的迷你虚拟机环境。
2、安装
2.1、安装方法
2.1.1、通过APT安装
在Debian
上进行安装,命令如下:
apt install -y supermin
2.1.2、通过yum安装
yum install -y supermin*
2.2、安装结果
3、使用方法
3.1、查看帮助
root@l:~# supermin --help
supermin - tool for creating supermin appliances
Copyright (C) 2009-2014 Red Hat Inc.
Usage:
supermin --prepare LIST OF PACKAGES ...
supermin --build INPUT [INPUT ...]
For full instructions, read the supermin(1) man page.
Options:
--build Build a full appliance
--copy-kernel Copy kernel instead of symlinking
--dtb Obsolete option, do not use
-f chroot|ext2 Set output format
--format -"-
--host-cpu ARCH Set host CPU architecture
--if-newer Only build if needed
--include-packagelist Add a file with the list of packages
--list-drivers Display list of drivers and exit
--lock LOCKFILE Use a lock file
--names Give an error for people needing supermin 4
-o OUTPUTDIR Set output directory
--packager-config CONFIGFILE Set packager config file
--prepare Prepare a supermin appliance
--size Set the size of the ext2 filesystem
--use-installed Use installed files instead of accessing network
-v Enable debugging messages
--verbose -"-
-V Display version and exit
--version -"-
-help Display this list of options
--help Display this list of options
root@l:~#
3.2、常用步骤
1-准备(prepare )
->2-构建(build)
->3-生成tar包
->4-导入Docker
->5-运行容器
4、使用相关语法
4.1、准备(prepare )
执行这一步操作之后,会生成一个文件夹保存所需文件信息,类似一个Dockerfile
supermin -v --prepare ${需要的包} -o ${保存的目录}
4.2、构建(build)
执行这一步之后,会生成一个文件保存这个迷你
系统文件,类似与把整个操作系统放在一个文件夹
supermin -v --build --format chroot ${第一步操作(prepare)保存的目录} -o ${保存构建信息的目录,即本次操作保存的目录}
4.3、生成tar包
执行这一步,就可以把第二步(build)生成的文件夹打包成一个tar
文件
tar --numeric-owner -cpf ${文件名.tar} -C ${第二步操作生成的文件夹} .
别忘了后面那个
点
4.4、导入Dockerr
这一步就是将tar
文件导入到Docker
镜像列表
cat ${文件名.tar} | docker import - ${Docker镜像名称:版本}
其中,第一,第二步中的
-v
是显示过程的意思,如果不需要看构建过程就删除就行了
5、实践演示
5.1、准备(prepare )
root@l:~# supermin -v --prepare bash net-tools apt dpkg vim -o debian10.d
supermin: version: 5.1.20
supermin: package handler: debian/dpkg
supermin: prepare: bash net-tools apt dpkg vim
supermin: packages specified on the command line:
- bash_5.0-4_amd64
- net-tools_1.60+git20180626.aebd88e-1_amd64
- apt_1.8.2.2_amd64
- dpkg_1.19.7_amd64
- vim_2:8.1.0875-5_amd64
supermin: writing debian10.d.qi9uwl1q/packages
supermin: after resolving dependencies there are 57 packages:
- adduser_3.118_all
- apt_1.8.2.2_amd64
- base-files_10.3+deb10u9_amd64
- bash_5.0-4_amd64
- debconf_1.5.71_all
- debian-archive-keyring_2019.1+deb10u1_all
- debianutils_4.8.6.1_amd64
- dpkg_1.19.7_amd64
- gcc-8-base_8.3.0-6_amd64
- gpgv_2.2.12-1+deb10u1_amd64
- libacl1_2.2.53-4_amd64
- libapt-pkg5.0_1.8.2.2_amd64
- libattr1_1:2.4.48-4_amd64
- libaudit-common_1:2.8.4-3_all
- libaudit1_1:2.8.4-3_amd64
- libbz2-1.0_1.0.6-9.2~deb10u1_amd64
- libc6_2.28-10_amd64
- libcap-ng0_0.7.9-2_amd64
- libdb5.3_5.3.28+dfsg1-0.5_amd64
- libffi6_3.2.1-9_amd64
- libgcc1_1:8.3.0-6_amd64
- libgcrypt20_1.8.4-5_amd64
- libgmp10_2:6.1.2+dfsg-4_amd64
- libgnutls30_3.6.7-4+deb10u6_amd64
- libgpg-error0_1.35-1_amd64
- libgpm2_1.20.7-5_amd64
- libhogweed4_3.4.1-1_amd64
- libidn2-0_2.0.5-1+deb10u1_amd64
- liblz4-1_1.8.3-1_amd64
- liblzma5_5.2.4-1_amd64
- libnettle6_3.4.1-1_amd64
- libp11-kit0_0.23.15-2+deb10u1_amd64
- libpam-modules-bin_1.3.1-5_amd64
- libpam-modules_1.3.1-5_amd64
- libpam0g_1.3.1-5_amd64
- libpcre3_2:8.39-12_amd64
- libseccomp2_2.3.3-4_amd64
- libselinux1_2.8-1+b1_amd64
- libsemanage-common_2.8-2_all
- libsemanage1_2.8-2_amd64
- libsepol1_2.8-1_amd64
- libstdc++6_8.3.0-6_amd64
- libsystemd0_241-7~deb10u7_amd64
- libtasn1-6_4.13-3_amd64
- libtinfo6_6.1+20181013-2+deb10u2_amd64
- libudev1_241-7~deb10u7_amd64
- libunistring2_0.9.10-1_amd64
- libzstd1_1.3.8+dfsg-3+deb10u2_amd64
- net-tools_1.60+git20180626.aebd88e-1_amd64
- passwd_1:4.5-1.1_amd64
- perl-base_5.28.1-6+deb10u1_amd64
- tar_1.30+dfsg-6_amd64
- vim-common_2:8.1.0875-5_all
- vim-runtime_2:8.1.0875-5_all
- vim_2:8.1.0875-5_amd64
- xxd_2:8.1.0875-5_amd64
- zlib1g_1:1.2.11.dfsg-1_amd64
Get:1 http://mirrors.tencentyun.com/debian buster/main amd64 adduser all 3.118 [240 kB]
Get:2 http://mirrors.tencentyun.com/debian buster/main amd64 apt amd64 1.8.2.2 [1419 kB]
Get:3 http://mirrors.tencentyun.com/debian buster/main amd64 libattr1 amd64 1:2.4.48-4 [21.3 kB]
Get:4 http://mirrors.tencentyun.com/debian buster/main amd64 libaudit-common all 1:2.8.4-3 [22.4 kB]
Get:5 http://mirrors.tencentyun.com/debian buster/main amd64 base-files amd64 10.3+deb10u9 [69.9 kB]
Get:6 http://mirrors.tencentyun.com/debian buster/main amd64 bash amd64 5.0-4 [1378 kB]
Get:7 http://mirrors.tencentyun.com/debian buster/main amd64 debconf all 1.5.71 [145 kB]
Get:8 http://mirrors.tencentyun.com/debian buster/main amd64 debian-archive-keyring all 2019.1+deb10u1 [93.5 kB]
Get:9 http://mirrors.tencentyun.com/debian buster/main amd64 dpkg amd64 1.19.7 [2208 kB]
Get:10 http://mirrors.tencentyun.com/debian buster/main amd64 libc6 amd64 2.28-10 [2867 kB]
Get:11 http://mirrors.tencentyun.com/debian buster/main amd64 libsemanage-common all 2.8-2 [17.7 kB]
Get:12 http://mirrors.tencentyun.com/debian buster/main amd64 libpam-modules amd64 1.3.1-5 [309 kB]
Get:13 http://mirrors.tencentyun.com/debian buster/main amd64 passwd amd64 1:4.5-1.1 [1005 kB]
Get:14 http://mirrors.tencentyun.com/debian buster/main amd64 vim-common all 2:8.1.0875-5 [195 kB]
Fetched 9990 kB in 0s (24.8 MB/s)
W: Download is performed unsandboxed as root as file '/var/tmp/superminba6fe3.tmpdir/bjlplhmw/adduser_3.118_all.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
supermin: there are 51 config files
supermin: writing debian10.d.qi9uwl1q/base.tar.gz
./etc/selinux/semanage.conf
./etc/libaudit.conf
./etc/security/access.conf
./etc/security/group.conf
./etc/security/limits.conf
./etc/security/namespace.conf
./etc/security/namespace.init
./etc/security/pam_env.conf
./etc/security/sepermit.conf
./etc/security/time.conf
./etc/xattr.conf
./etc/apt/apt.conf.d/70debconf
./etc/debconf.conf
./etc/cron.daily/passwd
./etc/default/useradd
./etc/pam.d/chfn
./etc/pam.d/chpasswd
./etc/pam.d/chsh
./etc/pam.d/newusers
./etc/pam.d/passwd
./etc/vim/vimrc
./etc/apt/trusted.gpg.d/debian-archive-bullseye-automatic.gpg
./etc/apt/trusted.gpg.d/debian-archive-bullseye-security-automatic.gpg
./etc/apt/trusted.gpg.d/debian-archive-bullseye-stable.gpg
./etc/apt/trusted.gpg.d/debian-archive-buster-automatic.gpg
./etc/apt/trusted.gpg.d/debian-archive-buster-security-automatic.gpg
./etc/apt/trusted.gpg.d/debian-archive-buster-stable.gpg
./etc/apt/trusted.gpg.d/debian-archive-stretch-automatic.gpg
./etc/apt/trusted.gpg.d/debian-archive-stretch-security-automatic.gpg
./etc/apt/trusted.gpg.d/debian-archive-stretch-stable.gpg
./etc/deluser.conf
./etc/ld.so.conf.d/x86_64-linux-gnu.conf
./etc/debian_version
./etc/dpkg/origins/debian
./etc/host.conf
./etc/issue
./etc/issue.net
./etc/update-motd.d/10-uname
./etc/alternatives/README
./etc/cron.daily/dpkg
./etc/dpkg/dpkg.cfg
./etc/logrotate.d/alternatives
./etc/logrotate.d/dpkg
./etc/apt/apt.conf.d/01autoremove
./etc/cron.daily/apt-compat
./etc/kernel/postinst.d/apt-auto-removal
./etc/logrotate.d/apt
./etc/bash.bashrc
./etc/skel/.bash_logout
./etc/skel/.bashrc
./etc/skel/.profile
supermin: renaming debian10.d.qi9uwl1q to debian10.d
root@l:~# lls de^C
root@l:~#
root@l:~# ls debian10.d/
base.tar.gz packages
5.2、构建(build)
root@l:~# ls
debian10.d
root@l:~# supermin -v --build --format chroot debian10.d -o appliance.d
supermin: version: 5.1.20
supermin: package handler: debian/dpkg
supermin: build: debian10.d
supermin: reading the supermin appliance
supermin: build: visiting debian10.d/base.tar.gz type gzip base image (tar)
supermin: build: visiting debian10.d/packages type uncompressed packages
supermin: mapping package names to installed packages
supermin: resolving full list of package dependencies
supermin: build: 57 packages, including dependencies
supermin: build: 4824 files
supermin: build: 4824 files, after matching excludefiles
supermin: build: 4824 files, after adding hostfiles
supermin: build: 4824 files, after removing unreadable files
supermin: build: 4831 files, after munging
supermin: renaming appliance.d.493rjl3g to appliance.d
root@l:~# ls
appliance.d debian10.d
root@l:~# ls appliance.d/
bin boot dev etc home lib lib64 proc root run sbin sys tmp usr var
root@l:~# cat appliance.d/etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
5.3、生成tar
root@l:~# tar --numeric-owner -cpf Debian10.tar -C appliance.d/ .
root@l:~# ls
appliance.d debian10.d Debian10.tar
5.4、导入镜像
root@l:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress bak 052a9c25158d 5 days ago 5.42GB
<none> <none> 08fc3b149d0f 5 days ago 5.42GB
wordpress latest fa58a354af43 8 days ago 550MB
daxia/websafe latest 47e2d8835d02 17 months ago 673MB
teezily/ftpd latest 2be98c038950 3 years ago 10.4MB
root@l:~# cat Debian10.tar | docker import - liuyi/debian:10
sha256:92e8ba2e442490e820a5d21a7d0d8d02f4c7c12344a6cf37ccbe3bba7e75af6e
root@l:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
liuyi/debian 10 92e8ba2e4424 2 seconds ago 102MB
wordpress bak 052a9c25158d 5 days ago 5.42GB
<none> <none> 08fc3b149d0f 5 days ago 5.42GB
wordpress latest fa58a354af43 8 days ago 550MB
daxia/websafe latest 47e2d8835d02 17 months ago 673MB
teezily/ftpd latest 2be98c038950 3 years ago 10.4MB
5.5、运行容器
root@l:~# docker run -ti --rm liuyi/debian:10 bash
I have no name!@dd28514c6312:/# I have no name!@dd28514c6312:/#
I have no name!@dd28514c6312:/# cat /etc/os-release
bash: cat: command not found
I have no name!@dd28514c6312:/# more /etc/os-release
bash: more: command not found
I have no name!@dd28514c6312:/#
最后,在准备阶段一定要把常用工具丢上去,例如:sed
、cat
、vi
、apt
之类