golang-app/Dockerfile

44 lines
995 B
Docker
Raw Normal View History

FROM golang:alpine as builder
2022-07-20 01:05:08 +03:00
LABEL org.opencontainers.image.authors="psssix <psssix@gmail.com>"
# set build environmet variables needed for multistage building
ENV CGO_ENABLED=0 \
GOOS=linux
# source workdir
WORKDIR /source
# Copy and download dependency using go mod
# Vendoring
COPY go.mod go.sum ./
RUN go mod download
# Copy the code into the container
COPY . .
# Some different way for vendoring
#RUN go mod tidy && go mod vendor
# Build the application
RUN go build -o build/app .
FROM scratch
# Move to /app directory as the place for resulting binary folder
WORKDIR /
# Copy binary from build to main folder
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2022-07-20 01:05:08 +03:00
COPY --from=builder /source/build/app app
# Copy some application assets
2022-07-20 01:05:08 +03:00
#COPY ./database/data.json /database/data.json
# Export necessary port
#EXPOSE 3000
ENTRYPOINT ["/app"]
# Command to run when starting the container
#CMD ["/app"]
# if have not application daemon
#CMD tail -f /dev/null