Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use docker buildx bake to build docker compose containers for both linux/armv7 and linux/amd64

I have developed a primarily raspberry pi app in Python that uses Redis as its local cache so naturally I turned to docker compose to define all my services i.e. redis and my app. I am using Docker Hub private repository to host my container. But I do not get how to use the docker buildx bake command to target linux/armv7 platform as --platform flag is not part of bake

All the examples that the Docker team has shown use the simple docker buildx command which cannot be run for compose files.

My docker-compose.yml file is defined as:

version: '3.0'
services:
  redis:
    image: redis:alpine

  app:
    image: dockerhub/repository
    build: gateway
    restart: always

Dockerfile:

# set base image (Host OS)
FROM python:3.8-slim

# set the working directory in the container
WORKDIR /run

# copy the dependencies file to the working directory
COPY requirements.txt .

# install dependencies
RUN pip install -r requirements.txt

# copy the content of the local src directory to the working directory
COPY src/ .

# command to run on container start
CMD [ "python", "-u", "run.py" ]

Any help would be much appreciated. Thanks

like image 879
m.umar Avatar asked Dec 06 '25 03:12

m.umar


1 Answers

you can supply platform parameter under key xbake as mentioned below. (reference document: https://docs.docker.com/engine/reference/commandline/buildx_bake/)

# docker-compose.yml
services:
  addon:
    image: ct-addon:bar
    build:
      context: .
      dockerfile: ./Dockerfile
      args:
        CT_ECR: foo
        CT_TAG: bar
      x-bake:
        tags:
          - ct-addon:foo
          - ct-addon:alp
        platforms:
          - linux/amd64
          - linux/arm64
        cache-from:
          - user/app:cache
          - type=local,src=path/to/cache
        cache-to: type=local,dest=path/to/cache
        pull: true

  aws:
    image: ct-fake-aws:bar
    build:
      dockerfile: ./aws.Dockerfile
      args:
        CT_ECR: foo
        CT_TAG: bar
      x-bake:
        secret:
          - id=mysecret,src=./secret
          - id=mysecret2,src=./secret2
        platforms: linux/arm64
        output: type=docker
        no-cache: true
like image 142
Shreeniwas Kulkarni Avatar answered Dec 09 '25 10:12

Shreeniwas Kulkarni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!