上次分享了一下怎么制作centos的镜像,今天给大家分享一下ubuntu的制作方法。
准备ubuntu环境
如果你有Ubuntu环境的话最好,可以直接打包,我用的是CentOS系统,所以需要借助debootstrap工具。
bash
yum -y install epel-release
yum -y install debootstrap
mkdir ~/ubuntu-root
debootstrap --arch=amd64 focal ~/ubuntu-root http://archive.ubuntu.com/ubuntu/
[root@bogon ]# ls ~/ubuntu-root/
bin dev home lib32 libx32 mnt proc run srv tmp var
boot etc lib lib64 media opt root sbin sys usr
制作ubuntu镜像
bash
mkdir ubuntu
cd ubuntu
mv ~/ubuntu-root .
cat > Dockerfile << EOF
FROM scratch
ADD ubuntu-root/ /
CMD ["/bin/bash"]
EOF
docker build -t ubuntu .
[root@bogon ubuntu]# docker build -t ubuntu .
[+] Building 0.3s (5/5) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 87B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build context 0.3s
=> => transferring context: 1.08MB 0.3s
=> CACHED [1/1] ADD ubuntu-root/ / 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:80026197be11ccce07f1be9707d39540bc4fda056b6119d6d 0.0s
=> => naming to docker.io/library/ubuntu 0.0s
测试
bash
[root@bogon ~]# docker run -it --rm ubuntu bash
root@25befe3b3054:/#