I am experiencing problems with a very basic use-case. My image works fine when I do a local-push using balena push uuid.local --emulated.
But when I deploy it with balena deploy myApp --logs --source . --emulated --build --nocache my container won’t start due to the following error:
standard_init_linux.go:207: exec user process caused “exec format error”
My Dockerfile is completely basic. And inside the /html folder there is just one static html file.
FROM nginx:1.17.1-alpine
COPY /html /usr/share/nginx/html
As far as I know the error indicates it targets the wrong architecture. But I am using --emulated.
I do see this in the build/deploy logs:
[Info] Docker Desktop detected (daemon architecture: “x86_64”)
[Info] Docker itself will determine and enable architecture emulation if required,
[Info] without balena-cli intervention and regardless of the --emulated option.
Also tried building and deploying in separate steps with specifying device and aarch with no results.
@gerb0n, I think what is happening is that the base image (nginx:1.17.1-alpine) uses Docker Hub “manifests” to differentiate between architectures (like amd64 vs. arm64v8), but the balena CLI still does not understand those manifests and requires different image tags, or the full sha256 hash to be specified (issue 1508).
Emulation does not help / apply because emulation is used while building the image, in order to execute RUN instructions in a Dockerfile. The Dockerfile you’ve shared (thanks!) does not even contain RUN instructions, and in any case the balena CLI --emulated flag is ignored when Docker Desktop is used (because Docker Desktop uses binfmt_misc in order to run the RUN instructions in the Dockerfile).
The workaround I suggest is to add the sha256 hash of the intended architecture (arm64v8 for the RPi 4) to the FROM line. The sha256 hash can be found in Docker Hub, browsing the tags for the nginx image and filtering for 1.17.1-alpine:
So a “good” Dockerfile for the RPi4 would probably be:
FROM nginx:1.17.1-alpine@sha256:ba0713e56ea1d0ce7aad766529dda12c2e47e1fcb2b6ee0079ada8c575873c3a
COPY /html /usr/share/nginx/html
I tested the Dockerfile above with balena deploy and an RPi4, and it avoids the exec format error message (which happens if I use the amd64 hash, or no hash).
Let us know if this workaround works for you. You can also subscribe to GitHub notifications for issue 1508.