使用 buildx 构建多架构镜像

Windows和Mac的桌面版Docker自带buildx命令,但是Linux环境下的Docker需要自行安装buildx (https://github.com/docker/buildx

https://docs.docker.com/buildx/working-with-buildx/

本节课使用的源码 https://github.com/xiaopeng163/flask-redis

登录dockerhub

  1. docker login

进入源码目录(Dockerfile所在目录)

  1. git clone https://github.com/xiaopeng163/flask-redis
  2. cd flask-redis

构建

  1. PS C:\Users\Peng Xiao\flask-redis> docker login
  2. Authenticating with existing credentials...
  3. Login Succeeded
  4. PS C:\Users\Peng Xiao\flask-redis> docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 -t xiaopeng163/flask-redis:latest .
  5. [+] Building 0.0s (0/0)
  6. error: multiple platforms feature is currently not supported for docker driver. Please switch to a different driver (eg. "docker buildx create --use")
  7. PS C:\Users\Peng Xiao\flask-redis>
  8. PS C:\Users\Peng Xiao\flask-redis> docker buildx ls
  9. NAME/NODE DRIVER/ENDPOINT STATUS PLATFORMS
  10. desktop-linux docker
  11. desktop-linux desktop-linux running linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
  12. default * docker
  13. default default running linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
  14. PS C:\Users\Peng Xiao\flask-redis> docker buildx create --name mybuilder --use
  15. mybuilder
  16. PS C:\Users\Peng Xiao\flask-redis> docker buildx ls
  17. NAME/NODE DRIVER/ENDPOINT STATUS PLATFORMS
  18. mybuilder * docker-container
  19. mybuilder0 npipe:////./pipe/docker_engine inactive
  20. desktop-linux docker
  21. desktop-linux desktop-linux running linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
  22. default docker
  23. default default running linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
  24. PS C:\Users\Peng Xiao\flask-redis> docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 -t xiaopeng163/flask-redis:latest .