Docker: Difference between revisions
From Timon's Wiki
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 2: | Line 2: | ||
=== Builder Setup === | === Builder Setup === | ||
Install QEMOU to allow emulation of different arches. Using emulation is not the most efficient way to build an image. See | Install QEMOU to allow emulation of different arches. Using emulation is not the most efficient way to build an image. See [https://docs.docker.com/build/building/multi-platform/#qemu Docker docs] for more other ways.<syntaxhighlight lang="shell"> | ||
docker run --privileged --rm tonistiigi/binfmt --install all | docker run --privileged --rm tonistiigi/binfmt --install all | ||
</syntaxhighlight>Creating the new builder:<syntaxhighlight lang="shell"> | </syntaxhighlight>Creating the new builder:<syntaxhighlight lang="shell"> | ||
docker buildx create --name <Name> --bootstrap --use | docker buildx create --name <Name> --bootstrap --use | ||
</syntaxhighlight>Replace <code><Name></code> with a different name. The Flag <code>--use</code> will automaticity select the builder as default. Running <code>docker buildx ls</code> should show your new builder with | </syntaxhighlight>Replace <code><Name></code> with a different name. The Flag <code>--use</code> will automaticity select the builder as default. Running <code>docker buildx ls</code> should show your new builder, with available platforms. | ||
=== Building an Image === | === Building an Image === | ||
Latest revision as of 12:38, 2 January 2025
Multi-arch Build
Builder Setup
Install QEMOU to allow emulation of different arches. Using emulation is not the most efficient way to build an image. See Docker docs for more other ways.
docker run --privileged --rm tonistiigi/binfmt --install all
Creating the new builder:
docker buildx create --name <Name> --bootstrap --use
Replace <Name> with a different name. The Flag --use will automaticity select the builder as default. Running docker buildx ls should show your new builder, with available platforms.
Building an Image
Edit your Dockerfile to select the arch depending on the build argument.
- FROM alpine:latest
+ ARG ARCH=
+ FROM ${ARCH}alpine:latest
Now you can build your image using
docker buildx build --push --platform linux/arm64/v8,linux/amd64/v3 --tag OWNER/IMAGE:VERSION .
This will build the image in the current directory for arm64 & amd64 and push it into the registry to OWNER/IMAGE:VERSION.
