Docker pull from different source for different architecture

1.1k views Asked by At

I have a Dockerfile that pulls FROM hivemq/hivemq-ce. This works well on "standard" platforms but not on the Raspberry Pi. So I built the image for arm64 myself directly on the RasPi following the tutorial in the official HiveMQ repo and pushed it to my private docker registry. The Dockerfile works well on RasPi if I change the FROM line to FROM my-private-registry/hivemq-ce.

So now I have images that work on different platforms in different sources. But how can I make my Dockerfile work on all platforms? Is there any way to pull from different sources for different architectures?

2

There are 2 answers

2
maxm On BEST ANSWER

As outlined here docker supports multiple cpu architectures and will select the correct image for the correct platform. So you could build a non arm64 image for frederikheld/hivemq-ce and push it to the same location without affecting the arm64 image.

You should be able to run docker manifest inspect frederikheld/hivemq-ce to see the available architectures for a given image.

0
Fred On

I went with this approach:

start.sh:

...
if [ "$(uname -m)" = "aarch64" ]; then
    docker-compose -f docker-compose.aarch64.yml up -d --build --force-recreate
else
    docker-compose up -d --build --force-recreate
fi
...

This requires one standard docker-compose.yml and additional docker-compose.<architecture>.yml for each architecture that has different needs.

It's not great, but it works in my environment.

I'm still open for better solutions though!