欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

docker buildx 安装和使用

程序员文章站 2022-07-14 10:28:20
...

1、安装
下载docker
https://editor.csdn.net/md/?articleId=109290013

2、安装buildx

https://github.com/docker/buildx/releases/tag/v0.5.1
wget https://github.com/docker/buildx/releases/download/v0.5.1/buildx-v0.5.1.linux-amd64
mkdir  -p  ~/.docker/cli-plugins
mv buildx-v0.5.1.linux-amd64 ~/.docker/cli-plugins/docker-buildx
chmod a+x ~/.docker/cli-plugins/docker-buildx
echo "export DOCKER_CLI_EXPERIMENTAL=enabled"  > /etc/profile
export DOCKER_CLI_EXPERIMENTAL=enabled

vi /etc/docker/daemon.json

{
  "registry-mirrors": ["https://dockerhub.azk8s.cn", "https://docker.mirrors.ustc.edu.cn"], 
  "experimental": true,     #启用docker体验功能
  "insecure-registries": ["127.0.0.1/8","0.0.0.0/0","harbor.cadp.com","harbor.kids.cn:18088","mmzwwwdocker.xxxxxx.com:31104","19.15.115.4:31104"],    #配置非安全镜像仓库
  "max-concurrent-downloads": 10,
  "log-driver": "json-file",
  "log-level": "warn",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
    },
  "data-root": "/var/lib/docker"
}

3、安装qemu

  • 修改yum源为阿里云
cd /etc/yum.repos.d
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repobak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget https://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache
yum install qemu -y

4、qemu 与docker集成
如果你使用的是 Linux,需要手动启用 binfmt_misc。大多数 Linux 发行版都很容易启用,不过还有一个更容易的办法,直接运行一个特权容器,容器里面写好了设置脚本:

docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64

建议将 Linux 内核版本升级到 4.x 以上,特别是 CentOS 用户,你可能会遇到错误。
centos7 可手动添加以下进行集成

echo ':qemu-arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm:' >/proc/sys/fs/binfmt_misc/register

echo ":qemu-aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64:" >/proc/sys/fs/binfmt_misc/register

确认结果

[[email protected] devops]# ls -al /proc/sys/fs/binfmt_misc
total 0
drwxr-xr-x 2 root root 0 Mar 29 18:11 .
dr-xr-xr-x 1 root root 0 Mar 19 17:36 ..
-rw-r--r-- 1 root root 0 Mar 29 19:05 qemu-aarch64       #已确认集成
-rw-r--r-- 1 root root 0 Mar 29 19:07 qemu-arm           #已确认集成
--w------- 1 root root 0 Mar 29 19:07 register
-rw-r--r-- 1 root root 0 Mar 29 18:11 status

5、buildx与centos7集成
增加以下配置
mkdir -p /root/.docker/buildx
vi /root/.docker/buildx/buildkitd.toml

debug = true
# root is where all buildkit state is stored.
root = "/var/lib/buildkit"
# insecure-entitlements allows insecure entitlements, disabled by default.
insecure-entitlements = [ "network.host", "security.insecure" ]

[registry."19.15.14.158:31104"]
  mirrors = ["19.15.14.158:31104"]
  http = true       #使用http协议
  insecure = true    #不验证安全证书
[registry."mmzwwwdocker.xxxxxx.com:31104"]
  mirrors = ["mmzwwwdocker.xxxxxxx.com:31104"]
  http = true  #使用http协议
  insecure = true  #不验证安全证书
#使用buildx 创建新的工作空间
docker buildx create --config=/root/.docker/buildx/buildkitd.toml --name gdczt --platform linux/amd64,linux/arm64  
#docker pull mmzwwwdocker.xxxxxxx.com:31104/public/buildkit:buildx-stable-1
#docker tag  mmzwwwdocker.xxxxxxx.com:31104/public/buildkit:buildx-stable-1  moby/buildkit:buildx-stable-1
docker buildx inspect gdczt --bootstrap
docker buildx use gdczt 
  • 验证
[[email protected] devops]# docker buildx ls
NAME/NODE DRIVER/ENDPOINT             STATUS  PLATFORMS
gdczt *   docker-container                #成功使用gdczt工作空间
  gdczt0  unix:///var/run/docker.sock running linux/amd64*, linux/arm64*, linux/386
default   docker                              
  default default                     running linux/amd64, linux/386

6、DNS解释的问题
本环境使用了k8s,所以使用coredns进行解决
其它方法参考“http://article.nxpop.com/col/7699.html

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
data:
  Corefile: |
    .:53 {
        errors
        health {
          lameduck 5s
        }
        ready
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
        }
        hosts {
            173.16.194.13 gitlab.digitalgd.com           #域名解释
            19.15.14.158 mmzwwwdocker.xxxxxxx.com
            fallthrough
        }
        prometheus :9153
        forward . "/etc/resolv.conf"
        cache 30
        loop
        reload
        loadbalance
        log
    }
相关标签: 容器化