docker如何构建多架构(arm64, x86_64, armv7)容器镜像?

1. 更新docker的版本到大于或等于19.03

1.1 x86下如何更新docker?

$ sudo apt install -y apt-transport-https
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update
$ sudo apt-get install docker-ce

1.2 检查以下docker的版本

$ docker --version

2. 编辑~/.docker/config.json文件来使能这个处于实验阶段的buildx功能

$ cat ~/.docker/config.json
{
   "experimental": "enabled"
}

3. switch to a different driver

$ sudo docker buildx create --user

4. 开始构建(保证当前目录下有Dockerfile文件)

$ sudo docker buildx build --platform linux/amd64,linux/arm64,linux/armv7 -t test_demo:1.0 .

5. 参考资料

https://github.com/docker/buildx/#installing