Testing multi-stage build and single file docker image
This commit is contained in:
17
Dockerfile
17
Dockerfile
@ -1,10 +1,8 @@
|
||||
# specify the base image to be used for the application
|
||||
FROM golang:1.21.4-alpine
|
||||
# Build stage
|
||||
FROM golang:1.21.4-alpine AS builder
|
||||
|
||||
# create the working directory in the image
|
||||
WORKDIR /app
|
||||
|
||||
# copy Go modules and dependencies to image
|
||||
COPY go.mod ./
|
||||
|
||||
# download Go modules and dependencies
|
||||
@ -13,11 +11,14 @@ RUN go mod download
|
||||
# copy all the Go files ending with .go extension
|
||||
COPY *.go ./
|
||||
|
||||
# compile application
|
||||
RUN go build -o /golang-http-header
|
||||
RUN go build -o golang-http-header
|
||||
|
||||
# Final stage
|
||||
FROM scratch
|
||||
|
||||
COPY --from=builder /app/golang-http-header /
|
||||
|
||||
# network port at runtime
|
||||
EXPOSE 8000
|
||||
|
||||
# execute when the container starts
|
||||
CMD [ "/golang-http-header" ]
|
||||
CMD ["/golang-http-header"]
|
Reference in New Issue
Block a user