skip to Main Content

I’m trying to write a very simple and straightforward docker file for a Golang application. But for some reason it is giving me this error when trying to run the image:

exec /app/serverTest: no such file or directory

I can’t figure out what is wrong with it, searched for similar questions but no luck solving the issue.

Here’s my dockerfile:

## Build
FROM golang:1.20 AS build

WORKDIR /tmp/build

COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

RUN go build -o ./out/serverTest .

## Deploy
FROM golang:alpine

COPY --from=build /tmp/build/out/serverTest /app/serverTest

EXPOSE 8080

ENTRYPOINT ["/app/serverTest"]

I’ve tried giving +x permissions, using CMD instead of ENTRYPOINT, changing names/folders, among other things..

Some idea on what the problem could be?

2

Answers


  1. Chosen as BEST ANSWER

    Seems like the executable file wont run with alpine. Dunno why, but if I change golang:alpine to debian:latest, it works


  2. Try to build with:

    CGO_ENABLED=0 go build -o ./out/serverTest .
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search