Long story short
docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx build --push --tag user/image-name --platform=linux/arm64,linux/amd64 .
Initial situation
I was still in the early stages of diving into the Mac world when I noticed that there was a new PHPBB3 version and I wanted to add it to my docker image. No sooner said than done, new version and new sha256 verifier hacked into the Dockerfile and straight away
docker build . -t <imageTag>
After the build, which went smoothly and successfully as expected, test the whole thing locally. Simply start the forum with the prepared docker-compose.yaml, everything works great. So put the image in the DockerHub and quickly run a docker / docker-compose pull on the server and that’s it: the forum is no longer accessible. The disaster now began.
Research
At first I assumed that it was the software itself, i.e. that the existing data couldn’t handle the new version, since I tested locally with an empty database of course. So I dug through the logs to find a cause, but upon closer inspection I could only find error messages that didn’t make any sense at first, because different components complained that they couldn’t find folders or weren’t allowed to write to them or, or or.
We’re getting closer
All folders were there with the appropriate rights, so that can’t be the problem. So I asked myself the question: What is the difference from before?
- New software version
- I didn’t build the image under Linux:
- I’ve often read about problems with M1 chips or necessary platform-specific anomalies.
So at least a clue and a little research has shown that we need to look at buildx, after I also saw many entries like DOCKER_BUILDKIT=0 COMPOSE_DOCKER_CLI_BUILD=0 docker command etc. But why would I want to switch off build-kit, docker is platform independent at least in theory. And build-kit also seems to have a right to exist? So we just need to understand the tools given to us and use them correctly.
The problem
Docker builds should actually be built for the linux/amd64 platform by default, but this was not the case in my normal, freshly installed Docker desktop environment (yes, I was too lazy to just install the docker engine). So the image was simply built for the wrong platform and this was the reason why the Linux server running on Docker couldn’t do anything with the image. And since I was previously working in a homogeneous landscape, Linux PC and Linux server, I never thought about it.
The solution
As I said, correctly use the tools given to us:
docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx build --push --tag user/image-name --platform=linux/arm64,linux/amd64 .
What do we do with those three lines up there?
- Line 1: Create a new builder with the name: mybuilder
- Line 2: tell buildx to use mybuilder
- Line 3: Run the docker build with buildx and push the image directly into the registry and here we also specify the platform(s) for which this image should be built. That’s the solution to the puzzle. If I still find the error messages, I’ll add them to this post.
![[EN] Mein erstes Docker Image mit dem M1 MacBook](/images/docker_apple_not_linux.png)