Skip to content

Instantly share code, notes, and snippets.

Embed
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
@ngauthier

This comment has been minimized.

Copy link
Owner Author

@ngauthier ngauthier commented Feb 2, 2015

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