This is an old revision of the document!
client1:~/gowebd# cat main.go
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
http.HandleFunc("/", HelloServer)
fmt.Printf("Starting server at port 8080\n")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
}
func HelloServer(w http.ResponseWriter, r *http.Request) {
name, err := os.Hostname()
if err != nil {
panic(err)
}
fmt.Fprint(w, "Hello world from " + name + "\n")
}
client1:~/gowebd# cat Dockerfile
FROM golang #FROM golang as builder WORKDIR /build COPY main.go . RUN go mod init gowebd RUN go build -o /gowebd #FROM alpine #COPY --from=builder /gowebd /gowebd ENTRYPOINT ["/gowebd"]