Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created February 2, 2015 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngauthier/ed3deeea8bd2cb038293 to your computer and use it in GitHub Desktop.
Save ngauthier/ed3deeea8bd2cb038293 to your computer and use it in GitHub Desktop.
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
@ngauthier
Copy link
Author

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