[Golang] Create Dockerfile for golang app
Containerizing the application is very popular nowadays and it makes the deployment so easy. This post will show how to create a Dockerfile for golang application. There are basically two steps in the Dockerfile: Build the golang program source code Containerize the golang app binary # Build source code FROM golang:1.18-alpine AS build WORKDIR /go/src/github.com/app COPY . . RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux go build -a -o main . # Containerize the binary FROM alpine COPY --from=build /go/src/github.com/app/main . EXPOSE 3500 CMD ["/main"] Exporting the port 3500 is because golang app listens to 3500. Here is just an example. ...