https://github.com/intob/jgocker
My FROM scratch for Go
https://github.com/intob/jgocker
docker
Last synced: 3 months ago
JSON representation
My FROM scratch for Go
- Host: GitHub
- URL: https://github.com/intob/jgocker
- Owner: intob
- Created: 2024-02-12T19:34:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-08T23:39:48.000Z (about 1 year ago)
- Last Synced: 2025-03-15T08:04:09.282Z (3 months ago)
- Topics: docker
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
```dockerfile
# Thanks to https://github.com/chemidy/smallest-secured-golang-docker-image
#
# STEP 1 build executable binary
#
FROM golang:alpine as builder# Set the current working directory inside the container
WORKDIR /app# Copy app files
COPY . /app# 1. Install git, ca-certs, and timezone data
# 2. Write commit hash to a file
# 3. Build the static binary
RUN apk update \
&& apk add --no-cache \
git \
ca-certificates \
tzdata \
&& update-ca-certificates \
&& git rev-parse --short HEAD > commit \
&& CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags='-w -s -extldflags "-static"' \
-mod=readonly \
-a \
-o yourapp .#
# STEP 2 build small image
#
FROM scratch# Copy zoneinfo for time zone support
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
# Copy ca-certs for SSL support
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
# Copy binary and app files
COPY --from=builder /app/yourapp /yourapp
COPY --from=builder /app/commit /commitENTRYPOINT ["/yourapp"]
```