/golang-docker-alpine

Building and Deploying Minimize Golang Executable Docker Image with Alpine Linux

Primary LanguageGo

golang-docker-alpine

Travis CI

Introduction

A template for deploying a minimize golang binary docker image, which size only about 10 MB.

This example uses Travis CI and Heroku to make a demo.

Docker version higher than 17.05

Use multi-stage builds, the example Dockerfile

Docker version lower than 17.05

Make two docker file

  • DockerSrc for building binary
  • DockerBin for execution

See the example in old folder

Comparison

Image Size
source code image 282 MB
binary image 10.5 MB

Warning

Function time.LoadLocation() will panic in binary image, because of

LoadLocation looks in the directory or uncompressed zip file named by the ZONEINFO environment variable, if any, then looks in known installation locations on Unix systems, and finally looks in $GOROOT/lib/time/zoneinfo.zip.

You have to set $GOROOT and copy zoneinfo.zip manually.

Reference