|
| 1 | +# Guide for building multi-arch docker images |
| 2 | + |
| 3 | +## Creating a `docker buildx` build config |
| 4 | + |
| 5 | +To build for both amd64 and aarch4 (e.g. for running on Apple |
| 6 | +Silicon), you can use `docker buildx`. |
| 7 | + |
| 8 | +First, you will need to create a buildx config, because the default |
| 9 | +one does not seem to work well for cross-platform builds. Here we name |
| 10 | +that config `multiarch`, but it can be named anything. |
| 11 | + |
| 12 | +We have found that using the `kubernetes` driver works better than the |
| 13 | +default `docker-container` driver. |
| 14 | + |
| 15 | +```shell |
| 16 | +docker buildx create --name multiarch --use --driver kubernetes --driver-opt=qemu.install=true |
| 17 | +``` |
| 18 | + |
| 19 | +The `--use` part tells buildx to set this as the default builder. |
| 20 | + |
| 21 | +_Note_: We tell docker buildx to use qemu, so that the amd64 images |
| 22 | +can be built on an aarch64 host. |
| 23 | + |
| 24 | +_Warning_: If your KUBECONFIG env var is colon-separated, this is |
| 25 | +something that `docker buildx` apparently does not support. You will |
| 26 | +need to run any `docker buildx` commands with |
| 27 | +e.g. `KUBECONFIG=~/.kube/config`, i.e. pointing it to a single |
| 28 | +filepath. |
| 29 | + |
| 30 | +## Starting a build |
| 31 | + |
| 32 | +Now you should be able to build and push: |
| 33 | + |
| 34 | +```shell |
| 35 | +# whatever you need here, but note that the Dockerfiles |
| 36 | +# may need to change, as you update these image names and tags |
| 37 | +TAG=ghcr.io/project-codeflare/custodian:0.0.1 |
| 38 | + |
| 39 | +# build for aarch64 (arm64/v8) and amd64 |
| 40 | +PLATFORMS=linux/arm64/v8,linux/amd64 |
| 41 | + |
| 42 | +# note here that we build and push in one step; for some reason, |
| 43 | +# buildx fails when only building |
| 44 | +docker buildx build --push --platforms $PLATFORMS --tag $TAG . |
| 45 | +``` |
0 commit comments