containerd环境下build镜像
安装container和nerdctl和buildkit
https://blog.youkuaiyun.com/omaidb/article/details/128677718
buildkit
项目地址:https://github.com/moby/buildkit
nerdctl
也可以和 buildkit
结合使用来构建容器镜像。
使用nerdctl构建docker镜像
参考:
https://developer.aliyun.com/article/1094835
https://mp.weixin.qq.com/s/Bjn0s5qRh2H9I__mAYh4jg
修改Dockerfile
https://blog.youkuaiyun.com/omaidb/article/details/121434775
构建镜像
# 构建镜像
./Dockerfile |nerdctl build -t 镜像名:tag
# 构建镜像
nerdctl build -t 镜像名:tag .
# 查看构建好的镜像
nerdctl images
containerd配置代理
老是替换源太麻烦了,直接上代理
https://segmentfault.com/a/1190000020363043
# 创建/etc/systemd/system/containerd.service.d目录
mkdir /etc/systemd/system/containerd.service.d
# 配置代理
cat > /etc/systemd/system/containerd.service.d/proxy.conf << EOF
> [Service]
> Environment="HTTP_PROXY=socks5://127.0.0.1:1080"
> Environment="HTTPS_PROXY=socks5://127.0.0.1:1080" "NO_PROXY=localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8,docker-registry.somecorporation.com,isdp30x2.mirror.aliyuncs.com,hub-mirror.c.163.com,mirror.baidubce.com"'
> EOF
# 重启containerd服务
systemctl daemon-reload
systemctl restart containerd
# 查看配置的代理
systemctl show --property=Environment containerd.service
containerd配置代理ansible剧本
---
- hosts: all
tasks:
- name: 创建containerd.service.d目录
file:
path: /etc/systemd/system/containerd.service.d
state: directory
- name: 创建proxy.conf文件
file:
path: /etc/systemd/system/containerd.service.d/proxy.conf
state: touch
- name: 为http_proxy.conf文件添加配置信息
copy:
content: |
[Service]
Environment="HTTP_PROXY=socks5://127.0.0.1:1080"
Environment="HTTPS_PROXY=socks5://127.0.0.1:1080" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com,isdp30x2.mirror.aliyuncs.com,hub-mirror.c.163.com,mirror.baidubce.com"
dest: /etc/systemd/system/containerd.service.d/proxy.conf
notify: 重启containerd服务
handlers:
- name: 重启containerd服务
systemd:
state: restarted
daemon_reload: yes
name: containerd