buildkit

安装 buildkit

1
2
3
wget https://github.com/moby/buildkit/releases/download/v0.15.1/buildkit-v0.15.1.linux-amd64.tar.gz
tar zxvf buildkit-v0.15.1.linux-amd64.tar.gz
mv ./bin/* /usr/local/bin

启动buildkitd服务,使用--oci-worker=false --containerd-worker=true参数,可以让 buildkitd 服务使用 containerd 后端

1
buildkitd --oci-worker=false --containerd-worker=true &

使用

dockerfile

1
2
FROM dockerhub.qingcloud.com/doubao/nginx
LABEL doubao=cute

构建镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
root@devops:~/data# buildctl build \
--frontend=dockerfile.v0 \
--local context=. \
--local dockerfile=. \
--output type=image,name=dockerhub.qingcloud.com/doubao/nginx:doubao
[+] Building 0.5s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 97B 0.0s
=> [internal] load metadata for dockerhub.qingcloud.com/doubao/nginx:latest 0.3s
=> [auth] doubao/nginx:pull token for dockerhub.qingcloud.com 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [1/1] FROM dockerhub.qingcloud.com/doubao/nginx:latest@sha256:c94f3436f3bfcb467e9723bdb4957e2e86c00cc5f21e38a40d668c1a4c324696 0.0s
=> => resolve dockerhub.qingcloud.com/doubao/nginx:latest@sha256:c94f3436f3bfcb467e9723bdb4957e2e86c00cc5f21e38a40d668c1a4c324696 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => exporting manifest sha256:1fee4f91e595af322b8aaf7b3d74a1de6de0e12798097631b1e2fc063a3818dc 0.0s
=> => exporting config sha256:70fddb68d1e838d671f94e3c579b75e81d6e4717fc25e3c8decec405cf3b7f67 0.0s
=> => naming to dockerhub.qingcloud.com/doubao/nginx:doubao

查看本地镜像,这个docker无法查看到,可以使用ctr来查看,ctr是有namespace概念的

1
2
3
4
5
root@devops:~/data# ctr -n buildkit i ls
REF TYPE DIGEST SIZE PLATFORMS LABELS
dockerhub.qingcloud.com/doubao/nginx:doubao application/vnd.docker.distribution.manifest.v2+json sha256:1fee4f91e595af322b8aaf7b3d74a1de6de0e12798097631b1e2fc063a3818dc 67.7 MiB linux/amd64 -
root@devops:~/data#

推送到远程仓库里面

1
2
3
4
5
root@devops:~/data# ctr -n buildkit i push -u username:password dockerhub.qingcloud.com/doubao/nginx:doubao
manifest-sha256:1fee4f91e595af322b8aaf7b3d74a1de6de0e12798097631b1e2fc063a3818dc: done |++++++++++++++++++++++++++++++++++++++|
config-sha256:70fddb68d1e838d671f94e3c579b75e81d6e4717fc25e3c8decec405cf3b7f67: done |++++++++++++++++++++++++++++++++++++++|
elapsed: 2.4 s total: 8.9 Ki (3.7 KiB/s)
root@devops:~/data#