Difficulty: intermediate
Estimated Time: 10 minutes

In this scenario you'll learn how to compile your Go code as part of the image build step

Well done! Now you can build your application into a small and efficient image with one build command.

Go apps and multistage image builds

Step 1 of 3

Write a simple web server

Start by writing a simple Go web server application.

Hello world

Write a basic web server in Go that will respond to a request on port 8080 with a simple message like "hello world". The editor pane on the top right of this screen is already set up to edit a file called hello.go. You can click the button below to copy the code into that file.

package main

import (
  "fmt"
  "os"
)

func main() {
    fmt.Printf("Here are my arguments: %v\n", os.Args[:])
}

Next step

We're not going to compile this code into a binary by running go manually on the command line. In the next step you'll see how to do the compilation step within a container image build.

hello.go
Dockerfile