using cmd docker compose up inside testdocker folder.
here is my dockerfile
# golang base image
FROM golang:1.19-alpine as golangBase
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN go mod tidy && go build -o handlerBuild main.go
FROM ubuntu:latest
RUN mkdir /app
WORKDIR /app
COPY --from=golangBase /app .
ENTRYPOINT [ "/app/handlerBuild" ]
here is my docker-compose.yml
having file structure like below /testdocker
/testdocker/main.go
/testdocker/go.mod
/testdocker/dockerfild
/testdocker/docker-compose.yml
Edit:
found the solution here, needed flag CGO_ENABLED=0
, while building.
Go-compiled binary won't run in an alpine docker container on Ubuntu host