aardvark.code
Docker helloworld.go
What?
Compile a go application, build it into a container and run it. Simple! This also shows how a configuration value ('YOURNAME') can be passed from the docker command line to the container on startup.
Prerequisite
To run this aardvark.code example you need to have following software installed on your system:
Go aardvark
Grab this aardvark.code
file:
wget http://data.munging.ninja/aardvarkcode/docker/aardvark.code
Execute
Output of the 'build' :
--- Compiling -----------------------------------------------
--- Build container -----------------------------------------
Sending build context to Docker daemon 75.15 MB
Sending build context to Docker daemon
Step 0 : FROM debian
---> 37c816ae4431
Step 1 : COPY helloworld .
---> bd81fc9a712e
Removing intermediate container 49887fffeea8
Step 2 : RUN chmod +x ./helloworld
---> Running in 52600566c5e8
---> 166b57edb033
Removing intermediate container 52600566c5e8
Step 3 : ENTRYPOINT ./helloworld
---> Running in 3e274e23d561
---> 952283f977f7
Removing intermediate container 3e274e23d561
Successfully built 952283f977f7
Output of running the container:
--- Run container -------------------------------------------
Yo CarréConfituurke, today is Saturday!
The aardvark.code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
##== tmp/helloworld.go =========================================================
package main
import (
"fmt"
"time"
"os"
)
func main() {
day := time.Now().Weekday ()
name :=os.Getenv("YOURNAME" )
fmt.Printf ("Yo %v, today is %v!\n" , name, day)
}
##== tmp/helloworld.dockerfile =================================================
FROM debian
COPY helloworld .
ENTRYPOINT [ "./helloworld" ]
##== aardvark.sh ===============================================================
#!/bin/bash
echo "--- Compiling -----------------------------------------------"
go build tmp/helloworld.go
echo "--- Build container -----------------------------------------"
docker build -f tmp/helloworld.dockerfile -t helloworld:v1 .
echo "--- Run container -------------------------------------------"
docker run -e YOURNAME=CarréConfituurke helloworld:v1