Skip to content

Instantly share code, notes, and snippets.

@daumie daumie/Dockerfile
Created Aug 6, 2019

Embed
What would you like to do?
Docker instructions to build and package a simple Go application.
FROM golang:latest as builder
# Application working directory ( Created if it doesn't exist )
WORKDIR /build
# Copy all files ignoring those specified in dockerignore
COPY . /build/
# Installing custom packages from github
RUN go get -d github.com/prometheus/client_golang/prometheus/promhttp
# Execute instructions on a new layer on top of current image. Run in shell.
RUN CGO_ENABLED=0 go build -a -installsuffix cgo --ldflags "-s -w" -o /build/main
FROM alpine:3.9.4
# metadata for better organization
LABEL app="go-helloworld"
LABEL environment="production"
# Set workdir on current image
WORKDIR /app
# Leverage a separate non-root user for the application
RUN adduser -S -D -H -h /app appuser
# Change to a non-root user
USER appuser
# Add artifact from builder stage
COPY --from=builder /build/main /app/
# Expose port to host
EXPOSE 8080
# Run software with any arguments
ENTRYPOINT ["./main"]
@mbrowne

This comment has been minimized.

Copy link

mbrowne commented Mar 27, 2020

The -h /app part in the adduser command doesn't do anything, because -H tells it not to create a home directory. I'm not sure I understand the intention here. But this is a helpful example overall :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.