standard_init_linux.go:178: exec user process caused "exec format error" kubernetes

6/10/2018

I know this issue has been encountered by many people, but none of the given answers resolved my issue.

Workflow

  • I run all my dockers in a kubernetes cluster (google cloud).
  • I've setup the compilation_trigger to auto build my dockerfile when I commit in my master branch on github.
  • Then I update my kubernetes deployment with kubectl set image deployment/MYPROJECT MYPROJECT=eu.gcr.io/foo/MYPROJECT:$TRAVIS_COMMIT

Whats wrong ?

My pod stays in crashloop back-off and in the logs I read: standard_init_linux.go:178: exec user process caused "exec format error"

A bit of context

My workflow used to work untill the begining of June 2018, I don't understand what's wrong so Ive searched on the internet, modified my dockerfile, updated my dependencies, changed the dockerfile base image version, etc... Nothing works

Dockerfile

FROM golang:1.10-alpine3.7 AS builder
ADD . /go/src/github.com/foo/MYPROJECT
WORKDIR /go/src/github.com/foo/MYPROJECT/api
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -a -installsuffix cgo -o /go/bin/api

FROM alpine:3.7
RUN apk --no-cache add ca-certificates
COPY --from=builder /go/bin/api /go/bin/api
COPY --from=builder /go/src/github.com/foo/MYPROJECT/api/sql /go/migrations/sql
COPY --from=builder /go/src/github.com/foo/MYPROJECT/api/.docs/swagger.yml /static/swagger.yml
RUN chmod +x /go/bin/api
ENTRYPOINT ["/go/bin/api"]

[EDIT: 12 June]

I noticed the docker image size went from 6.3 Mo to 2.3 Mo when the problem started. I suspect an update from alpine, I continue to investigate.

-- GwydionFR
docker
go
kubernetes

2 Answers

6/12/2018

Ok I found the issue. I post it here, in case someone is stupid like me. I made a change in my github repository, transforming 1 project/microservices into 1 monorepo for every microservices. During the refactor, I had no package main in my api microservice, and the go build DID NOT fail, but wrote a file of 90 Ko in the output destination.

SOLUTION

Ensure to have a main package

I feel really stupid but hey, it happens to everyone.

Thank you to commentators, you were right

-- GwydionFR
Source: StackOverflow

5/27/2019

Although not the solution to this question, another cause may be if your command is a script without shebang.

-- Anne van der Bom
Source: StackOverflow