Skip to content

Instantly share code, notes, and snippets.

Created February 2, 2015 15:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Static Golang Container via Tar
#!/usr/bin/env bash
# Makes a docker container for a static golang application.
# For a small app, this container is usually about 7mb.
# Usage:
# build-container myapp myuser/myapp cmd/myapp/main.go
set -e
# Version is the git sha for HEAD
version=$(git log -1 --format=format:%H)
mkdir -p tmp
# Statically linked binary for golang 1.4
CGO_ENABLED=0 go build -a -installsuffix cgo -o tmp/$1 $3
cd tmp
# Make tar containing the binary and import into docker under repo and tag
tar cv $1 | docker import - $2:$version
# Also retag latest
docker tag -f $2:$version $2:latest
Copy link

Then you can:

docker run myuser/myapp /myapp arg1 arg2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment