An example that shows how to build and use an extremely minimal Docker image (~ 5 MB) for a Go web service
- Go - a programming language that is fast, uses minimal resources and supports high concurrency
- Docker - container software
- Go is installed. To verify, run
go version
- GOPATH is set (e.g. set to
~/go
) - PATH includes
GOPATH/bin
Docker
is installed. To verify, rundocker --version
- clone repo or download zip
- in the project directory, run
make cleanrun
- check the image size with
docker images | grep pinbar/go-docker-minimal
- launch the browser and point to the baseurl
localhost:8080
- port can be changed in
main.go
andDockerfile
- port can be changed in
- use the make commands in the
Makefile
to start or stop the container
- the executable, which is fully statically linked, is built outside the container and then copied onto the image. This allows it to be able to run independently.
- since the base image is
scratch
, there are known TLS limitations that need a workaround - the target OS is set to
linux
but it can be changed in theMakefile