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
.
2
Answers
The image used in that example is already a multi-platform image. To check the arch of image, one can check the running container:
see docker ref: https://docs.docker.com/build/building/multi-platform
devops thread: https://devops.stackexchange.com/a/19307/24024
devtalk thread: https://forum.devtalk.com/t/docker-compose-dynamically-change-the-image-architecture-based-on-running-host-machine/155452/10?u=jaeyson
Not sure if you’re still looking for an answer, if so, I’ve outlined one here for you
https://github.com/devobs-ob/stackoverflow/tree/main/docker/DynamicImage-78493215
TLDR:
You can find instructions and the scripts in the Github repo linked above. Hope this helps and thanks for sharing your question.
— Ob