jaeyson

jaeyson

Docker Compose: dynamically change the image architecture based on running host machine

Hi! quick question: is it possible to dynamically change the image’s arch based on the host’s machine instead of create 2 separate docker compose file?

Currently I have 2 files:

For arm64 (osx)

services:
  typesense:
    image: docker.io/typesense/typesense:0.25.2-arm64
    container_name: typesense
    restart: on-failure
    ports:
      - "8108:8108"
    volumes:
      - ./typesense-data:/data
    command: '--data-dir /data --api-key=xyz --enable-cors'

For non arm64

services:
  typesense:
    image: docker.io/typesense/typesense:0.25.2
    container_name: typesense
    restart: on-failure
    ports:
      - "8108:8108"
    volumes:
      - ./typesense-data:/data
    command: '--data-dir /data --api-key=xyz --enable-cors'

The only difference here is the image, and ideally running them e.g. docker compose up -d then let the engine decide which arch is appropriate in the host’s machine instead of using docker compose -f <FILE> up -d.

Marked As Solved

conradwt

conradwt

There’s no platform option for docker compose. Thus, what you’re looking for here is something even easier. For example, you’ll want to do the following:

services:
  typesense:
    image: typesense/typesense:0.25.2
    container_name: typesense
    restart: on-failure
    ports:
      - "8108:8108"
    volumes:
      - ./typesense-data:/data
    command: '--data-dir /data --api-key=xyz --enable-cors'

Now, the above should run the appropriate Docker image platform variant for the host architecture.

Also Liked

jkdiaz

jkdiaz

I doubt that you can do this dynamically. Or maybe I am wrong. :slight_smile: But using separate files might be the simplest way.

faust

faust

I haven’t tried it myself but I guess you can use environment variables

image: docker.io/typesense/${MY_VARIABLE}"

Then in your shell you declare a variable called MY_VARIABLE according to your system

You can read more here:

conradwt

conradwt

@jaeyson Have you tried building a multi-platform Docker image for your application? If not, I recommend checking out the docs on the subject here:

Popular Cross Platform topics Top

jaeyson
Hi! quick question: is it possible to dynamically change the image’s arch based on the host’s machine instead of create 2 separate docker...
New

Other popular topics Top

Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
Author Spotlight Mike Riley @mriley This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New