Skip to content

Latest commit

 

History

History
139 lines (87 loc) · 4.17 KB

docker.md

File metadata and controls

139 lines (87 loc) · 4.17 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.

Svelte Kit

Two stage build

# syntax=docker/dockerfile:1.3
FROM node:18-alpine

WORKDIR /app

COPY . .

RUN --mount=type=cache,target=~/.npm npm ci && \
    npm audit fix && \
    npm run build


FROM node:18-alpine

WORKDIR /app

COPY --from=0 /app/package*.json ./

RUN --mount=type=cache,target=~/.npm npm ci --production --ignore-scripts && \
    npm audit fix

COPY --from=0 /app/build ./

EXPOSE 3000

USER 1000:1000

ENTRYPOINT ["node"]

CMD ["index.js"]