1. 概述
nerdctl想要构建镜像需要安装buildkit插件,且不能基于本地镜像进行构建,所以建议构建镜像和镜像仓库仍使用docker作为运行时。
2. 安装docker-ce
1 2 3
| [root@localhost ~] [root@harbor ~] [root@harbor ~]
|
3. 添加配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| [root@harbor ~] { "log-driver": "json-file", "log-opts": { "max-size": "100m", "max-file": "3" }, "max-concurrent-downloads": 10, "max-concurrent-uploads": 10, "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com"], "storage-driver": "overlay2", "storage-opts": [ "overlay2.override_kernel_check=true" ] }
|
4. 创建Dockerfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| [root@harbor ~] FROM hub.c.163.com/library/centos MAINTAINER ren RUN rm -rf /etc/yum.repos.d/* ADD repo.tar /etc/yum.repos.d/ RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-* && \ yum install net-tools iproute nginx -y && \ yum clean all && \ rm -rf /var/cache/yum/x86_64/* COPY index.html /usr/share/nginx/html/ ENV myname xxx VOLUME ["/data1","/data2"]
CMD ["nginx", "-g","daemon off;"]
|
5. 构建镜像
1
| docker build -t centos:v1 .
|
6. 容器构建层
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| [root@harbor ~] IMAGE CREATED CREATED BY SIZE COMMENT 2d27d9685011 2 minutes ago /bin/sh -c 78910337674c 2 minutes ago /bin/sh -c a08ee1b47ccb 2 minutes ago /bin/sh -c b113d86db0f8 2 minutes ago /bin/sh -c 3850648e9adc 2 minutes ago /bin/sh -c c4b8c4b6bb2f 2 minutes ago /bin/sh -c rpm --import /etc/pki/rpm-gpg/RPM… 57MB 921bf2371e22 54 minutes ago /bin/sh -c 478e859d1eb5 54 minutes ago /bin/sh -c rm -rf /etc/yum.repos.d/* 0B 88d815c24789 About an hour ago /bin/sh -c 328edcd84f1b 4 years ago /bin/sh -c <missing> 4 years ago /bin/sh -c <missing> 4 years ago /bin/sh -c
|
7. 测试镜像
1
| docker run -d --name nginx -p 80:80 nginx:v1
|