Compiling Your Go Application for Containers

Powerful Command-Line Applications in Go — by Ricardo Gerardi (123 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Cross-Compiling Your Application | TOC | Distributing Your Application as Sou rce Code 👉

Another alternative way to distribute your application that has become increasingly popular in recent years is allowing your users to run the application in Linux containers.[81] Containers package your application and all the required dependencies using a standard image format, and they run the application in isolation from other processes running on the same system. Containers use Linux kernel resources such as Namespaces and Cgroups to provide isolation and resource management.

There are different container runtimes available, such as Podman[82] and Docker.[83] If you’re running these examples on a Linux system, you can use either one interchangeably. If you’re running on Windows or macOS, Docker provides a desktop version that makes it easier to start. You can also use Podman on these operating systems, but you need to install a Virtual Machine to enable it. We’ll not cover a container runtime installation process here. For more details, check the respective project’s documentation.

To distribute your application as a container, you have to create a container image. You can do this in several ways, but a common way is by using a Dockerfile, which contains a recipe for how to create an image. Then you pass this file as input to docker or podman…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.