docker_practice/image/buildx_multi-arch-images.md

79 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 使 buildx Docker
Docker 使使 [`$ docker manifest`](manifest.md)
Docker 19.03+ 使 `$ docker buildx build` 使 `BuildKit`
`--platform` Docker
##
`buildx` 使
Linux/macOS
```bash
$ export DOCKER_CLI_EXPERIMENTAL=enabled
```
Windows
```bash
$ set $env:DOCKER_CLI_EXPERIMENTAL=enabled
```
## `builder`
Docker for Linux `arm` Docker
```bash
$ docker run --rm --privileged docker/binfmt:820fdd95a9972a5308930a2bdfb8573dd4447ad3
```
Docker `builder` `--platform` `builder`
```bash
$ docker buildx create --name mybuilder
$ docker buildx use mybuilder
```
##
Dockerfile
```docker
FROM --platform=$TARGETPLATFORM alpine
RUN uname -a > /os.txt
CMD cat /os.txt
```
使 `$ docker buildx build` `myusername` Docker Hub
`--push` Docker
```bash
$ docker buildx build --platform linux/arm,linux/arm64,linux/amd64 -t myusername/hello . --push
# 查看镜像信息
$ docker buildx imagetools inspect myusername/hello
```
```bash
# arm
$ docker run -it --rm myusername/hello
Linux buildkitsandbox 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018 armv7l Linux
# arm64
$ docker run -it --rm myusername/hello
Linux buildkitsandbox 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018 aarch64 Linux
# amd64
$ docker run -it --rm myusername/hello
Linux buildkitsandbox 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018 x86_64 Linux
```