

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
You may be thinking, "What's the point of dockerizing this simple service"? Well, at the moment, there are only a couple of benefits:
That said, because our app is so simple, there's just not much environment required, and one of the best things about Docker is that it allows you to ship an entire environment.
So... let's make it more interesting!
We're going to make the port that our server binds to configurable: it will be set by an environment variable.
port := os.Getenv("PORT")
Make sure that the os package is imported:
import (
"fmt"
"log"
"net/http"
"os"
"time"
)
export PORT="8999"
go build
./goserver
ENV PORT=8991
If you're not on Linux, rebuild the Go binary for Linux first: GOOS=linux GOARCH=amd64 go build
docker build . -t goserver:latest
docker run -p 8991:8991 goserver
Open http://localhost:8991 in your browser or curl it to confirm the container is serving on the Docker-set port.
Run and submit the CLI tests from your working directory against http://localhost:8991.