I am new to Docker and Kubernetes. I am going through some documentation and running the setup locally. I have some questions regarding that.
I created an image from a go file that prints "hello world". Here is the sample go file
package main
import (
"fmt"
"net/http"
)
func helloHandler(w http.ResponseWriter, r *http.Request) {
response := "Hello World!"
fmt.Fprintln(w, response)
fmt.Println("Processing hello request.")
}
func listenAndServe(port string) {
fmt.Printf("Listening on port %s\n", port)
err := http.ListenAndServe(":"+port, nil)
if err != nil {
panic("ListenAndServe: " + err.Error())
}
}
func main() {
http.HandleFunc("/", helloHandler)
port := "8080"
go listenAndServe(port)
select {}
}
Here is the Dockerfile
FROM golang:1.13
WORKDIR /go/src/hello
COPY ./hello.go /go/src/hello
CMD ["go","run","hello.go"]
This container is up and running. The container's IP address is stored in IP variable.
Now, in the documentation it says that we need a client container to test this service.
docker container run --rm busybox wget -qO- $IP:8080 && echo
Status: Downloaded newer image for busybox:latest
Hello World!
I am wondering why it needs this client container and when I the wget directly from my local machine, this does not work.
Any inputs. Thanks in advance for the help.