Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 566
don andreas Avatar asked Jan 15 '20 16:01

don andreas


People also ask

What is Docker buildx use <builder>?

docker buildx use <builder> will switch to the specified builder instance. The buildx instance performs build tasks in two ways, the two execution methods are referred to as using different drivers. docker driver: executes a build using the BuildKit library integrated in the Docker service application.

How do I build arm images in Docker?

In your docker file use base image with support for arm. E.g. ubuntu docker build --platform arm --pull -t your_tag . This command will force docker to pull arm version of the base image and will also set arm architecture to your result image.

What is the build element in Docker?

The build element define configuration options that are applied by Compose implementations to build Docker image from source. build can be specified either as a string containing a path to the build context or a detailed structure:

How do I build a specific target in Docker?

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.


1 Answers

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
like image 67
hennadiy.verkh Avatar answered Sep 23 '22 14:09

hennadiy.verkh