A template project to create a Docker image for a Go application. The example application exposes an HTTP endpoint and
This project is based on miguno/golang-docker-build-tutorial The Docker build uses a multi-stage build setup to minimize the size of the generated Docker image. The Go build uses dep for dependency management.
The only requirement for this running this example is that docker is installed.
- Use the included script to build the image inside the docker container
./app build
- Use the included script to run the image inside a docker container
./app run
# or you can specify a port number
# ./app run -p 3000
Two-stage build. The code is written on the local system then copied into the docker builder. The builder is a full golang docker image that is used to compile the code. The builder image is then discarded and the compiled binaries are placed into a minimal image (called scratch).
shell script. In order to facilitate the quick deployment of the app, I wrote a shell script for convenience to handle some of the messy internal workings. The internal configuration (specifically the container internal port number, image name, and image tag) are all configured within the app script.
Because I don't like hardcoding names into my dockerfile, I'm using python to do template substitution in the dockerfile. This is not standard but I want all the docker configuration to be ingested through some kind of logic to make sure everything is working as intended.
If you need SSL certificates for HTTPS, replace FROM SCRATCH
in the Docker file with:
FROM alpine:3.7
RUN apk --no-cache add ca-certificates
- Add the dockerfile templating tool
- Get the image to build successfully
- Launch a working hello world container