docker_practice/buildx/multi-arch-images.md

61 lines
1.9 KiB
Go
Raw Normal View History

# 使 buildx Docker
Docker 使使 [`$ docker manifest`](../image/manifest.md)
Docker 19.03+ 使 `$ docker buildx build` 使 `BuildKit` `--platform` Docker
## `builder`
Docker for Linux `arm` Docker
```bash
$ docker run --rm --privileged docker/binfmt:820fdd95a9972a5308930a2bdfb8573dd4447ad3
```
Docker `builder` `--platform` `builder`
```bash
2019-12-01 10:12:14 +08:00
$ docker buildx create --name mybuilder --driver docker-container
$ 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
```