Developing Go Apps With Docker
December 8, 2025 · 943 words · 5 min
Go (or Golang) is one of the most loved and wanted programming languages, according to . Thanks to
Go (or Golang) is one of the most loved and wanted programming languages, according to . Thanks to its smaller binary sizes vs. many other languages, developers often use Go for containerized application development. Mohammad Quanit explored the connection between Docker and Go . Mohammad shared how to Dockerize a basic Go application while exploring each core component involved in the process: Follow along as we dive into these containerization steps. We’ll explore using a Go application with an HTTP web server — plus key best practices, optimization tips, and ways to bolster security. Creating a full-fledged Go application requires you to create some Go-specific components. These are essential to many Go projects, and the containerization process relies equally heavily on them. Let’s take a closer look at those now. Mohammad mainly highlights the file since you can’t run an app without executable code. In Mohammad’s case, he created a simple web server with two unique routes: an I/O format with functionality, and one that returns the current time. What’s nice about Mohammad’s example is that it isn’t too lengthy or complex. You can emulate this while creating your own web server or use it as a stepping stone for more customization. You might also use a in place of a file. You don’t explicitly need specified for a web server — since you can name the file anything you want — but you do need a defined within your code. This exists in our sample above. We always recommend confirming that your code works as expected. Enter the command to spin up your application. You can alternatively replace with your file’s specific name. Then, open your browser and visit http://localhost:8081 to view your “Hello World” message or equivalent. Since we have two routes, navigating to http://localhost:8081/time displays the current time thanks to Mohammad’s second function. Next, we have the file. You’ll use this for your Go packages, module path for imports (shown above), and for dependency requirements. Go modules also help you choose a directory for your project code. With these two pieces in place, you’re ready to create your ! Building and deploying your Dockerized Go application means starting with a software image. While you can pull this directly from Docker Hub (using the CLI), gives you more configuration flexibility. You can create this file within your favorite editor, like . We recommend VS Code since it supports the official . This extension supports debugging, autocompletion, and easy project file navigation. Choosing a base image and including your application code is pretty straightforward. Since Mohammad is using Go, he kicked off his by specifying the as a parent image. Docker will build your final container image from this. You can choose whatever version you’d like, but a pinned version like is both stable and slim. Newer image versions like these are also safe from . You’ll also need to do the following within your : With these points in mind, here’s how Mohammad structured his basic : From here, you can run a quick CLI command to build your image from this file: This creates an image while removing any intermediate containers created with each image layer (or step) throughout the build process. You’re also tagging your image with a name for easier reference later on. Confirm that Docker built your image successfully by running the command: If you’ve already pulled or built images in the past and kept them, they’ll also appear in your CLI output. However, you can see Mohammad’s image listed at the top since it’s the most recent. What if you want to account for code or dependency changes that’ll inevitably occur with a production Go application? You’ll need to tweak your original and add some instructions, according to Mohammad, so that changes are visible and the build process succeeds: After making those changes, you’ll want to run the same and commands. Now, it’s time to run your new image! Enter the following command to start a container from your image: Confirm that this worked by entering the command, which generates a list of your containers. If you have Docker Desktop installed, you can also visit the tab from the Docker Dashboard and locate your new container in the list. This also applies to your image builds — instead using the tab. Congratulations! By tracing Mohammad’s steps, you’ve successfully containerized a functioning Go application. While our Go application gets the job done, Mohammad’s final image is pretty large at 913MB. The client (or end user) shouldn’t have to download such a hefty file. Mohammad recommends to only copy forward the components you need between image layers. Although we start with a as a builder image, defining a second build stage and choosing a slim alternative like helps reduce image size. You can to tackling this. This is beneficial and common across numerous use cases. However, you can take things a step further by using in your multi-stage builds. This empty file is the smallest we offer and accepts static binaries as executables — making it perfect for Go application development. You can learn more about our . Despite being on Hub, you can only add directly into your instead of pulling it. Mohammad Quanit outlined some user-friendly development workflows that can benefit both newer and experienced Go users. By following his steps and best practices, it’s possible to create cross-platform Go apps that are slim and performant. Docker and Go inherently mesh well together, and we also encourage you to explore what’s possible through containerization. Want to learn more?