'Changing the image in Docker Compose based on the host OS
I am creating a PHP app, and using Docker + Docker Compose to run it.
My problem is, I want users to be able to run my project on any OS with no hassle. However, the official mysql:latest
image is not supported on ARM processors (such as the Raspberry Pi), and so has to be switched out to hypriot/rpi-mysql
.
Is it possible to do this either within one Compose file or with separate files for each platform? Or will users have to manually swap in a YML file when they clone the project?
Solution 1:[1]
You can split your project into several YAML files, putting OS-independent stuff into one and dependent - into others. Your files will look like:
docker-compose.yml -- common stuff lives here
docker-compose-x64.yml -- lots of OS-dependent services for x64
docker-compose-arm.yml -- lots of OS-dependent services for arm
Then you just need to launch this in following manner:
# for x64
docker-compose -f docker-compose.yml -f docker-compose-x64.yml up ...
# for arm
docker-compose -f docker-compose.yml -f docker-compose-arm.yml up ...
Solution 2:[2]
FYI: There's a better answer to this now. You can build an image that supports multiple CPUs: https://docs.docker.com/desktop/multi-arch/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | grapes |
Solution 2 | Mike Patnode |