Skip to content

Commit

Permalink
Run the app in a scratch container
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Dec 27, 2023
1 parent 1b45c65 commit 9f4031b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1

FROM golang:1.21
FROM golang:alpine as app-builder

# Set destination for COPY
WORKDIR /app
Expand All @@ -20,7 +20,15 @@ COPY utils/ ./utils/
COPY views/ ./views/

# Build
RUN CGO_ENABLED=0 GOOS=linux go build
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags '-extldflags "-static"'

# Run in scratch container
FROM scratch
# the test program:
COPY --from=app-builder /app/instafix /instafix
# the tls certificates:
# NB: this pulls directly from the upstream image, which already has ca-certificates:
COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Optional:
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
Expand All @@ -29,5 +37,5 @@ RUN CGO_ENABLED=0 GOOS=linux go build
# https://docs.docker.com/engine/reference/builder/#expose
EXPOSE 3000

# Run
ENTRYPOINT ["/app/instafix"]
# Run the app
ENTRYPOINT ["/instafix"]

0 comments on commit 9f4031b

Please sign in to comment.