This image is based on the official golang:alpine image, and adds some features on top of it to enable baking your own golang applications into docker images.
- Go: 1.5.2
- Docker: 1.10.1
In this example the name of the resulting image is me/mygoapp, and it will have included some files and directories from the initial app source: conf.yml
, static
and views
. Including arbitrary directories or files from the source could be of a vital importance, if you are dockerizing a wep application, for example.
docker run --rm \
-v /host/your/project/source:/go/app \
-v /var/run/docker.sock:/var/run/docker.sock \
gobuilder \
-n me/mygoapp \
-d "conf.yml static views"
docker run me/mygoapp
-n
: The resulting image name. Required.-d
: A string with a space separated list of directories and/or files to be baked into the image. All paths must be relative to the project source directory.
This image is somewhat opinionated.
- Your Go application that is being built is supposed to use 'vendor' approach, i.e. keep all the dependencies inside 'vendor' directory. It is considered an experimental feature in Go 1.5. See more details here: https://golang.org/s/go15vendor
- Consequently, no
go get
will be performed when building the application. - The application is statically built into a single binary file.
- This binary file is then baked into a docker image that is based on scratch image. The resulting image is intended to be as small as possible.
Please, feel free to contribute to make this tool less opinionated and more configurable.
There is also an Ansible role to automate creation of a gobuilder image: https://github.com/meAmidos/ansible-build-go-builder