diff --git a/pages/containers/containers-8-extra-material.md b/pages/containers/containers-8-extra-material.md index 955fa389..96b0a305 100644 --- a/pages/containers/containers-8-extra-material.md +++ b/pages/containers/containers-8-extra-material.md @@ -11,10 +11,39 @@ resources: * An [early paper](https://arxiv.org/abs/1410.0846) on the subject of using Docker for reproducible research. -## More on volumes +## Building for multiple platforms -In the tutorial we mounted directories inside containers using the `-v -SOURCE:TARGET` syntax with `docker run`. We mentioned that volumes was a -more advanced way of handling data generated by containers... +With the newer ARM64 architectures introduced by Apple one often runs into the +problem of not having an architecture-native image to run with. This is +sometimes okay since the [Rosetta2](https://support.apple.com/en-us/HT211861) +software can emulate the old AMD64 architecture on newer ARM64 computers, but +results in a performance hit. One could just build for ARM64 using +`--platform=linux/arm64` instead, but then somebody who *doesn't* have the new +architecture can't run it. There is a way around this, however: *multi-platform +builds*. We can build for multiple platforms at the same time and push those to +*e.g.* DockerHub and anybody using those images will automatically pull the one +appropriate for their computer. Here's how to do it: -## Building for different platforms \ No newline at end of file +* Start by checking the available buildrs using `docker buildx ls`. + +You should only see the default builder, which does not have access to +multi-platform builds. Let's create a new builder that *does* have access to it: + +* Run the follownig: `docker buildx create --name mybuilder --driver + docker-container --bootstrap`. + +* Switch to using the new builder with `docker buildx use mybuilder` and check + that it worked with `docker buildx ls`. + +All that's needed now is to build and push the images! The following command +assumes that you have an account with `` at DockerHub and you're +pushing the `` image: + +```bash +docker buildx build --platform linux/amd64,linux/arm64 -t /:latest --push .` +``` + +* Execute the above command with your username and your image. + +That's it! Now anybody who does *e.g.* `docker pull /` will get +an image appropriate for their architecture whether they are on AMD64 or ARM64!