1. docker 版本> 1.20
2.配置buildx并启用:(有2种方式)
(1)修改配置文件:
修改:/etc/daemon.json,添加:
"experimental": true,
"features": {
"buildkit": true
}
(2)设置环境变量:
export DOCKER_CLI_EXPERIMENTAL=enabled
export DOCKER_BUILDKIT=1
3. 创建builder:(使用宿主机网络配置)
docker buildx create --use --name localbuilder --platform=linux/amd64,linux/arm64 --config=./buildkitd.toml --driver-opt=network=host
docker run --rm --privileged tonistiigi/binfmt:latest --install all
可用远程builder server:(远程server需要先配置免密登陆,使用ssh-copy-id -i root@xxx)
ARM64=ssh://root@10.xx.xx.xx
AMD64=ssh://root@10.xx.xx.xxx
## 注意: 这里指定名称 remotebuilder
DOCKER_HOST=${AMD64} docker buildx create --use --driver-opt network=host --name remotebuilder --node hk-amd64 --platform=amd64 --config=./buildkitd.toml
### --append 表示追加, 而非重新创建
DOCKER_HOST=${ARM64} docker buildx create --use --driver-opt network=host --append --name remotebuilder --node hk-arm64 --platform=arm64 --config=./buildkitd.toml
docker buildx use remotebuilder
docker buildx inspect remotebuilder --bootstrap
查看builder:
docker buildx inspect --bootstrap
buildkit配置文件buildkitd.toml:
insecure-entitlements = [ "network.host", "security.insecure" ]
[registry."docker.io"]
mirrors = ["wlzfs4t4.mirror.aliyuncs.com"]
insecure = true
http = false
[registry."harbor.userdefined.cn"]
http = false
insecure = true
4. harbor证书配置:
(1)添加rootCA.crt并信任:
ubuntu:
sudo cp rootCat.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates
centos:
sudo cp rootCa.crt /etc/pki/ca-trust/source/anchors/
sudo update-ca-trust
(2) 重启docker: sudo systemctl restart docker
(3) harbor证书:
cp tls.crt /etc/docker/cert.d/${harborhost}/
5. 编译镜像:
docker buildx build -f Dockerfile -t testimage:tag . --push (--load)
备注:x509错误解决:
docker cp /usr/local/share/ca-certificates/rootCa.crt ${moby/buildkit:buildx-stable}:/usr/local/share/ca-certificates/rootCa.crt
docker exec -t moby/buildkit:buildx-stable update-ca-certificates