standard_init_linux.go:211: exec user process caused "exec format error"

Viewed 159770

I am building the Dockerfile for python script which will run in minikube windows 10 system below is my Dockerfile

Building the docker using the below command docker build -t python-helloworld .

and loading that in minikube docker demon docker save python-helloworld | (eval $(minikube docker-env) && docker load)

Docker File

FROM python:3.7-alpine
#add user group and ass user to that group
RUN addgroup -S appgroup && adduser -S appuser -G appgroup

#creates work dir   
WORKDIR /app

#copy python script to the container folder app
COPY helloworld.py /app/helloworld.py

#user is appuser
USER appuser

ENTRYPOINT  ["python", "/app/helloworld.py"]

pythoncronjob.yml file (cron job file)

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: python-helloworld
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      backoffLimit: 5
      template:
        spec:
          containers:
          - name: python-helloworld
            image: python-helloworld
            imagePullPolicy: IfNotPresent
            command: [/app/helloworld.py]
          restartPolicy: OnFailure

Below is the command to run this Kubernetes job kubectl create -f pythoncronjob.yml

But getting the below error job is not running scuessfully but when u ran the Dockerfile alone its work fine

standard_init_linux.go:211: exec user process caused "exec format error"

8 Answers

This can also happen when your host machine has a different architecture from your guest container image.

E.g. running an arm container on a host with x86-64 architecture

I can see that you add the command command: [/app/helloworld.py] to yaml file.

so you need to (in Dockerfile):

RUN chmod +x /app/helloworld.py

set shebang to your py file:

#!/usr/bin/env python # whatever your defualt python to run the script

or setup the command the same as you did in Dockerfile

I recently encountered the problem when running a logstash container

standard_init_linux.go:211: exec user process caused "exec format error"

Noticed that the shebang line (#!/bin/sh) on the entrypoint.sh was typed in the second line instead of the first line of the entrypoint.sh file.

When the shebang line is made as to the first line in the script, the error went away and "docker run -it logstashimage:latest sh" worked perfectly.

For those on arm64 (Apple M1 ?) who want to compile for a production use, I managed to make it work with the --platform option of docker build.

docker build --platform linux/amd64 -t registry.gitlab.com/group/project:1.0-amd64 ./

you can, on the other way, choose linux/arm64.

I had this issue recently. Sharing my experience here. Basically I was trying to run a ARM docker image on X86_64 architecture.

Here is the steps I have followed

  1. Check host architecture

     uname -m # Display the host architecture
     #x86_64
    
     docker pull arm32v7/ubuntu # Get ARM docker image
    
     docker run --rm -t arm32v7/ubuntu uname -m
     standard_init_linux.go:211: exec user process caused "exec format error"
    
  2. Setting up ARM emulation on x86

Using QEMU allows us to to build ARM binaries on x86 machine without needing a cross compiler.

sudo apt-get install qemu binfmt-support qemu-user-static # Install the qemu packages
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes # This step will execute the registering scripts
  1. Run the docker image

    $ docker run --rm -t arm32v7/ubuntu uname -m
    armv7l
    

Reference : Building ARM container on x86

Rufus is correct, I came across this issue when attempting to build a x86 server image on my M1 MacBook which is arm64.

I was able to build for the correct target architecture by adding the "platform" attribute to my docker-compose.yml.

services:
    web:
        image: myimage/web:latest
        platform: linux/x86_64
        build:
            context: ./myfolder
            dockerfile: Dockerfile.prod

Another two reasons could raise this issue if you run docker on Windows:

  • scripts line endings are not LF (linux)
  • scripts encoding should be utf-8 + BOM

I met exactly the same error message. It was fixed by install qemu on the host machine. No idea about the reason.

Related