Building and using Golang applications with Docker
Golang is a great language able to create statically linked binaries for different platforms such as Linux (ELF binaries) or Mac OS (Mach-O binaries). These binaries are often very small in size, and the language is getting increasingly popular in the microservices world because of their portability and the speed of deployment it enables: deploying a self-sufficient 10 MB Docker image on dozens of servers is just more convenient and fast than a 1.5 GB image full of libs. Golang and containers are two technologies that go perfectly well together, and shipping or managing infrastructures using Go programs is a breeze.
Getting ready
To step through this recipe, you will need the following:
- A working Docker installation
- A Golang application source code
How to do it…
Let's say our application code is checked in src/hello
. We'd like to begin by at least compiling the program, either for the Linux platform or for the Mac operating system...