docker 打包centos 系统,创建docker 镜像
1.压缩系统相关目录,保留关键库,排查不需要的文件
tar -zcvf /var/tmp/mycentos.tar.gz \
--exclude=/boot/* \
--exclude=/proc/* \
--exclude=/dev/* \
--exclude=/sys/* \
--exclude=/home/* \
--exclude=/var/lib/* \
--exclude=/lib/modules/* \
--exclude=/var/cache/* \
--exclude=/project/* \
--exclude=/tmp/dxb/* \
--exclude=/root/gitlab* /
2.从压缩包导入docker镜像
docker load --input mycentos.tar.gz
遇到报错:open /var/lib/docker/tmp/docker-import-295614755/boot/json: no such file or directory
因为压缩包:只包含了layer.tar这个文件夹,缺少json这个文件夹
解决方法, 使用以下命令导入
cat mycentos.tar.gz | docker import - mycentos