skip to Main Content

I am trying to build this Dockerfile for Go Application and then deploy this to GKE but I’m seen this error upon pod creation. Upon describing this pod, I observed the same error.:

Error: failed to create containerd task: failed to create shim task:
OCI runtime create failed: runc create failed: unable to start
container process: exec: "./bin": stat ./bin: no such file or
directory: unknown

This image successfully run locally using this command.
docker run -it --rm bytecode01/domainalert:v2

#Dockerfile
FROM golang:alpine as builder
WORKDIR /data

COPY go.mod go.mod
RUN go mod download

# Copy the go source
COPY . .

# Build
RUN go build -a -o bin main.go

FROM alpine:latest

WORKDIR /data
COPY --from=builder /data/bin .
RUN chmod +x bin
CMD ["./bin"]

GKE PVC successfully mounted

#pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: de
  labels:
    name: de
spec:
  containers:
    - name: de-pod
      image: bytecode01/domainalert:v2
      imagePullPolicy: Always
      volumeMounts:
        - mountPath: /data
          name: app-volume
  volumes:
    - name: app-volume
      persistentVolumeClaim:
        claimName: pvc-dynamic
#pvc-dynamic.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-dynamic
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Mi
  storageClassName: standard

Help to get my issue solved.

2

Answers


  1. Your binary is located in ./data/bin:

    # Working directory is /data
    WORKDIR /data
    
    # Copies from "builder" to "." (==WORKDIR=/data)
    COPY --from=builder /data/bin .
    RUN chmod +x bin
    
    # Run from WORKDIR
    CMD ["./bin"]
    

    You then mount the PVC over it mountPath: /data effectively removing it.

    The solution is to put the binary (or mount the PVC) elsewhere.

    I encourage you to consider:

    1. using a name other than bin for your binary too. While it doesn’t cause the problem in this case, it could create problems and is non-descriptive.
    2. using ENTRYPOINT ["/path/to/you/binary"] rather than CMD [...]. This is documented extensively (including Docker’s ENTRYPOINT).
    FROM golang:alpine as builder
    WORKDIR /data
    
    COPY go.mod go.mod
    RUN go mod download
    
    # Copy the go source
    COPY . .
    
    RUN go build 
        -a 
        -o somethingdescriptive 
        main.go
    
    FROM alpine:latest
    
    COPY --from=builder /data/somethingdescriptive /bin
    
    ENTRYPOINT ["/bin/somethingdescriptive"]
    
    Login or Signup to reply.
  2. I believe this is due to an issue that was later documented in the GKE release notes here. Although the release notes indicate that the affected versions are listed below (Yours is on 1.27.8-gke.1067004) , I believe it is worth checking by disabling image streaming.

    For 1.27: 1.27.10-gke.1077000 and later
    For 1.28: All 1.28 versions
    For 1.29: All 1.29 versions

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search