22

I can build my dockerfile separately using following command:

docker buildx build --platform linux/arm64 -t testbuild .

now I want to use buildx in docker-compose file, but how, and how to say I want to use the arm64 architecture? This is the structure when I use the normal build.

testbuild:
build: …/testbuild
image: testbuild

Does anybody know?

4 Answers 4

12

You can use buildx in docker-compose by setting ENV variable COMPOSE_DOCKER_CLI_BUILD=1, also if buildx is not set as default, you should add DOCKER_BUILDKIT=1:

COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build
2
  • 2
    I think that enables BuildKit, not buildx
    – scytale
    Jun 25, 2021 at 11:38
  • Agree with @scytale, COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 enable buildx but they do not trigger the proper cross platform build. --platform does not work with docker-compose versions higher than 2.4
    – Jorge
    Mar 22, 2022 at 18:44
6

In docker-compose v2.4 was add attribute platform. Official documentation here.

Example:

version: '2.4'

services:
  testbuild:
    build: .../testbuild
    image: testbuild
    platform: linux/arm64/v8

P.S. Idk why, but it work only in docker-compose version 2.4

P.S.S About dockerx in docker-compose, he's not there. I think because dockerx is experimental feature in docker engine.

3

Try the docker buildx bake command. Official documentation says:

Use the -f / --file option to specify the build definition file to use. The file can be a Docker Compose, JSON or HCL file.

It also lets you pass the names of the targets to build, to build only specific targets.

3

Try

COMPOSE_DOCKER_CLI_BUILD=1 \
DOCKER_BUILDKIT=1 \
DOCKER_DEFAULT_PLATFORM=linux/amd64 \
docker-compose build

DOCKER_BUILDKIT

Enable (1) or disable (0) BuildKit builds

DOCKER_DEFAULT_PLATFORM

Set the default platform for commands that take the --platform flag

COMPOSE_DOCKER_CLI_BUILD

Configure whether to use the Compose built-in python client (0) for building images or the native docker cli (1). By default, Compose uses the docker CLI to perform builds, which allows you to use BuildKit to perform builds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.