I created a Golang backend and use a Makefile for common scripts. A snippet of the build command:
BINARY_NAME=myapp
MODULE_PATH=github.com/me/${BINARY_NAME}
BUILD_DIR=./build
build:
@go build -o $(BUILD_DIR)/$(BINARY_NAME)
I started with the following Dockerfile
# Build stage
FROM golang:1.21.0-bullseye AS build
WORKDIR /app
ADD . .
RUN make build
# Run stage
FROM alpine:3.18
WORKDIR /app
COPY --from=build /app/build/myapp .
# CMD [ "./myapp" ]
Building the image works fine but when trying to execute the binary I get the error that it’s missing. I tried to inspect the container, this is the output
❯ docker container run -it theimage
/app # ls
myapp
/app # ./myapp
/bin/sh: ./myapp: not found
So I can see the binary exists. But I don’t know why the container is not able to find it when I want to execute it.
Do you know what’s wrong or missing here?