Dockerize go programs

14 August, 2018 | sab

Assume this is the production grade program we need to dockerize and run.

package main

import "fmt"

func main() {
     fmt.Println("saying hello to the world")

FROM golang:1.10-alpine as builder
WORKDIR /go/src/
COPY main.go  .
COPY vendor ./vendor
RUN CGO_ENABLED=0 go build -o main .

FROM alpine:latest 
RUN apk --no-cache add ca-certificates
COPY --from=0 /go/src/ .
CMD ["./main"] 

Site design and logo and content ©