Building on docker on m1 => exec format error

Hi all.

Bit stumbed… I have the below makefile that I’m calling, also including my Dockerfile.
I’m getting

docker run -it --network devlab  georgelza/goprod-avro:1.0.0 runs_avro.sh
exec /app/runs_avro.sh: exec format error

Dockerfile

FROM bitnami/golang:1.22 AS base_arm64

LABEL Author="George Leonard (georgelza@gmail.com)"
ENV GOPROXY=https://proxy.golang.org,direct
ENV GOSUMDB=sum.golang.org

WORKDIR /app

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change

COPY go.mod ./
COPY go.sum ./
RUN go mod tidy

# RUN go get github.com/TylerBrock/colorjson
# RUN go get github.com/brianvoe/gofakeit
# RUN go get github.com/confluentinc/confluent-kafka-go/v2/kafka
# RUN go get github.com/confluentinc/confluent-kafka-go/v2/schemaregistry
# RUN go get github.com/confluentinc/confluent-kafka-go/v2/schemaregistry/serde
# RUN go get github.com/confluentinc/confluent-kafka-go/v2/schemaregistry/serde/avrov2
# RUN go get github.com/google/uuid
# RUN go get github.com/tkanos/gonfig
# RUN go get go.mongodb.org/mongo-driver/bson/bsonrw
# RUN go get go.mongodb.org/mongo-driver/mongo
# RUN go get go.mongodb.org/mongo-driver/mongo/options
# RUN go get go.mongodb.org/mongo-driver/mongo/readpref
# RUN go get google.golang.org/grpc/grpclog

###########START NEW IMAGE###################

FROM base_arm64 AS client

WORKDIR /app
COPY . .

RUN go build -v -o /app/cmd/ /app/cmd/main.go

#RUN GOOS=linux GOARCH=arm64 go build -v -o /app/cmd/ /app/cmd/main.go

###########START NE W IMAGE###################

FROM bitnami/golang:1.22 AS prod

WORKDIR /app
COPY --from=client /app/cmd/main /app/cmd/

COPY runs_avro.sh /app
ENV PATH=/app:/app/cmd:$PATH

CMD ["runs_avro.sh"]

Makefile

sudo docker build --platform linux/arm64 --no-cache -t ${BINARY_NAME}:${VERSION} .

This looks like it should be runs_avro.sh bug here

I’ve tried both these way to call the app:

#CMD ["main", "avro"]
# or
CMD ["runs_avro.sh"]

This is the contents of runs_avro.sh

. ./.pwd
#go run -v cmd/main.go avro
/app/cmd/main avro

have also tried the following as Dockerfile

FROM bitnami/golang:1.22 AS base_arm64

LABEL Author="George Leonard (georgelza@gmail.com)"
ENV GOPROXY=https://proxy.golang.org,direct
ENV GOSUMDB=sum.golang.org
WORKDIR /app

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change

COPY go.mod ./
COPY go.sum ./
RUN go mod tidy

###########START NEW IMAGE###################

FROM base_arm64 AS client
WORKDIR /app
COPY . .
RUN GOOS=linux GOARCH=arm64 go build -v -o /app/cmd/ /app/cmd/main.go

###########START NE W IMAGE###################
FROM bitnami/golang:1.22 AS prod
WORKDIR /app
COPY --from=client /app/cmd/main /app/cmd/

COPY runs_avro.sh /app
ENV PATH=/app:/app/cmd:$PATH

CMD ["main", "avro"]

Not EXACTLY sure why… but this worked…
Also by using the ubuntu:jammy image for production stage pulled final image size down to 90MB, vs the previous 500+MB when using golang:1.22.

Build command:

sudo docker build --platform linux/arm64 --no-cache -t ${BINARY_NAME}:${VERSION} .

Dockerfile

FROM golang:1.22 AS builder

ENV GOPROXY=https://proxy.golang.org,direct
ENV GOSUMDB=sum.golang.org

WORKDIR /build

COPY go.mod .
COPY go.sum .

RUN go mod download
COPY cmd/main.go .
COPY types ./types/
RUN go build -v -o ./main ./main.go

###########START NEW IMAGE###################

FROM ubuntu:jammy AS production

LABEL Author="George Leonard (georgelza@gmail.com)"

WORKDIR /app
COPY --from=builder /build/main .

CMD ["/app/main", "avro"]