MrE
MrE

Reputation: 20768

docker-compose multi arch

Docker images can be built for multi architectures. This is usually done by creating a specific image per architecture, and then creating manifest as a proxy to the right image depending on the system that pulls the image.

That's great.

Now, with docker-compose, it's also possible to build images, but I don't see a way to build the image depending on the architecture, so it seems like the only way to have a single docker-compose definition for multiple architectures, is to have pushed multi-arch images to a registry and pull from there.

Does anyone know of a way to build local images for the right arch with the docker-compose build step?

Upvotes: 17

Views: 16122

Answers (2)

Christian Ulbrich
Christian Ulbrich

Reputation: 3554

Although the docker docs states, that docker bake is still experimental, it seems to work nicely along with docker compose and some bake-specific yaml keys.

Given the following simple docker-compose.yml:

services:
  webapp:
    image: mycustom.registry/webapp
    build:
      context: ./
      dockerfile: Dockerfile

You can express in the docker-compose.yml the various target architectures, by adding x-bake "stuff" (sorry, not so much into yaml lingo), that are read by docker buildx bake:

services:
  webapp:
    image: mycustom.registry/webapp
    build:
      context: ./
      dockerfile: Dockerfile
      x-bake:
        platforms:
          - linux/amd64
          - linux/arm64

and run docker buildx bake for building all services having a build: in the docker-compose.yml and docker buildx bake --push to push them, that will be build for linux/amd64 and linux/arm64 respectively.

That way you can leverage other features that docker bake offers, like multiple tags per build or build cache configuration.

This seems to be a functionally complete replacement of docker compose build (apart from docker compose specific configuration merging I guess) and docker compose push. .env support seems to be equally available.

Upvotes: 1

3ch01c
3ch01c

Reputation: 2876

I don't think you can use docker-compose build, but you could use docker buildx bake to build multi-arch using a docker-compose.yml.

docker buildx bake --push --set *.platform=linux/amd64,linux/arm64

You'll probably want to read more about docker buildx bake and building multi-platform images.

Upvotes: 15

Related Questions