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.

16 1349 11

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...
16 1349 11
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
74 4699 41
New
ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
245 5146 101
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
110 3734 43
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
11 5156 4
New
AstonJ
Biggest jackpot ever apparently! :upside_down_face: I don’t (usually) gamble/play the lottery, but working on a program to predict the...
19 2926 10
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
49 4222 14
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
21 5424 9
New
PragmaticBookshelf
Author Spotlight Mike Riley @mriley This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
62 6186 19
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File &gt; New Rule: And select Deny, O...
5 7532 3
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
13 3660 10
New