As part of doing a few Go REST Services, for every project I usually put a Dockerfile to compile an run the project in a Docker container. The Dockerfile it’s always the same, just change it the project name, and I’m using godep.
So in DRY spirit a did a Minimal Viable Script to generate the Dockerfile for me, the project is in Github and I called godockerize.
The Dockerfile is based in the golang image, it follows these steps.
Is inspired by this two blog post.
$ go get github.com/dahernan/godockerize
# Go to the root directory of your project, for example
$ cd $GOPATH/src/github.com/dahernan/gopherscraper
# Run godockerize exposing the port 3001
$ godockerize -expose 3001
Dockerfile generated, you can build the image with:
$ docker build -t gopherscraper .
$ docker run --rm -p 3001:3001 -e ES=192.168.1.101 gopherscraper