Wayan Jimmy's Brain

Dockerize Golang App

related
Golang Docker

Example

Create a docker file, Dockerfile.local

FROM golang:1.13-alpine AS build
RUN go env -w GOPRIVATE=github.com/wayanjimmy/*

ARG GITHUB_USERNAME=username
ARG GITHUB_TOKEN=password

RUN apk update && apk add --no-cache git
RUN git config --global url."https://$GITHUB_USERNAME:$GITHUB_TOKEN@github.com".insteadOf "https://github.com"

WORKDIR /build
COPY . .
RUN go build -o app

FROM alpine:latest AS final

COPY --from=build /build/app /app

ENTRYPOINT ["/app"]

Build the docker image using this command

docker build -f Dockerfile.local --build-arg GITHUB_USERNAME=wayanjimmy --build-arg GITHUB_TOKEN=token -t wayanjimmy/reponame:latest .

Resources