Skip to content

Latest commit

 

History

History
102 lines (66 loc) · 3.7 KB

docker.md

File metadata and controls

102 lines (66 loc) · 3.7 KB

Docker

Tools

Utilities to be used inside containers

Development

Courses

Pin Docker version

apt-get install docker-ce="18.06.0ce3-0~ubuntu"

Base images

Security

Content trust

export DOCKER_CONTENT_TRUST=1

export DOCKER_BUILDKIT=1

Go

Two stage build from alpine and scratch

# syntax=docker/dockerfile:1.3
ARG GO_VERSION=1.17.2

FROM golang:${GO_VERSION}-alpine AS builder

RUN --mount=type=cache,target=/var/cache/apk apk add -U ca-certificates tzdata upx

WORKDIR /app
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod go mod tidy

COPY . .
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags='-s -w -extldflags "-static"' -o /app/app . && \
  upx /app/app

FROM scratch

COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /app/app /usr/bin/app

USER 65534:65534

ENTRYPOINT ["app"]

Second stage from distroless

FROM gcr.io/distroless/static

COPY --from=builder /app/app /app

USER nonroot:nonroot

ENTRYPOINT ["/app"]

Use :debug tag which providers busybox sh.