'Use buildx build linux/arm64 in docker-compose file
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?
Solution 1:[1]
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
Solution 2:[2]
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.
Solution 3:[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.
Solution 4:[4]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | hennadiy.verkh |
Solution 2 | |
Solution 3 | Pedro Francescon Cittolin |
Solution 4 | Aliaksandr Adzinets |