

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Dockerfiles
incomplete
2: Building a Server
incomplete
3: Dockerizing the Server
incomplete
4: Creating an Environment
incomplete
5: Python Script
incomplete
6: Dockerizing Python Error
incomplete
7: Dockerizing Python
incomplete
This lesson's interactive features are locked, please to keep using them
Now that we've built a very simple image from scratch, let's get a bit more real-world, but before we Dockerize anything, we'll first build and run a web server without a container.
This step is only about getting your Go server running locally.
If you want your commands to match ours in the following lessons, name your project "goserver".
Run and submit the CLI tests and then kill the server with Ctrl+C.
package main
import (
"fmt"
"log"
"net/http"
"time"
)
func main() {
m := http.NewServeMux()
m.HandleFunc("/", handlePage)
const port = "8010"
srv := http.Server{
Handler: m,
Addr: ":" + port,
WriteTimeout: 30 * time.Second,
ReadTimeout: 30 * time.Second,
}
// this blocks forever, until the server
// has an unrecoverable error
fmt.Println("server started on", port)
err := srv.ListenAndServe()
log.Fatal(err)
}
func handlePage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(200)
const page = `<html>
<head></head>
<body>
<p> Hello from Docker! I'm a Go server. </p>
</body>
</html>
`
w.Write([]byte(page))
}