My own app dockerized on my MacOS M1 Silicon host machine, fails with standard_init_linux.go:190: exec user process caused "exec format error"
when launched on Kubernetes cluster, with runs on Linux server.
I have my app with this Dockerfile:
FROM openjdk:11-jre-slim as jdkbase
FROM jdkbase
COPY app/target/dependency-jars /run/dependency-jars
COPY app/target/resources /run/resources
ADD app/target/app-1.0.3.jar /run/app-1.0.3.jar
CMD java -jar run/app-1.0.3.jar
,this docker-compose.yaml:
version: "3.8"
services:
myapp:
build:
context: .
dockerfile: myapp/Dockerfile
hostname: myapphost
and this pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- name: myapp-container
image: my.private.repo/app_dir/myapp:1.0.3
imagePullSecrets:
- name: st-creds
I've spent several hours trying to figure it out how to solve it, trying to use diff. variants of Entrypoints and cmds, but non of this was a working option.
The final solution was to build app for certain architecture, adding platform (platform: linux/amd64
) to the compose file:
version: "3.8"
services:
myapp:
platform: linux/amd64
build:
context: .
dockerfile: myapp/Dockerfile
hostname: myapphost
and also to change base image in the Dockerfile to any java image, which works with amd64, for example, to amd64/openjdk:11-slim
, like this:
FROM amd64/openjdk:11-slim as jdkbase
FROM jdkbase
COPY app/target/dependency-jars /run/dependency-jars
COPY app/target/resources /run/resources
ADD app/target/app-1.0.3.jar /run/app-1.0.3.jar
CMD java -jar run/app-1.0.3.jar
Hope this'll save time to anyone else who is new to Docker as me