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