Skip to content
Building and Deploying Minimize Golang Executable Docker Image with Alpine Linux
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
old
.travis.yml
Dockerfile
README.md
main.go

README.md

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

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.