Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterius committed Apr 28, 2023
2 parents 6d33064 + d179f77 commit 4da30ae
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions pages/containers/containers-8-extra-material.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* 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 `<username>` at DockerHub and you're
pushing the `<image>` image:

```bash
docker buildx build --platform linux/amd64,linux/arm64 -t <username>/<image>:latest --push .`
```

* Execute the above command with your username and your image.

That's it! Now anybody who does *e.g.* `docker pull <username>/<image>` will get
an image appropriate for their architecture whether they are on AMD64 or ARM64!

0 comments on commit 4da30ae

Please sign in to comment.