I cannot stop docker golang web server in docker container by sending Interrupt Signal. I have following main.go:
package main
import (
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello"))
})
log.Fatal(http.ListenAndServe(":1818", nil))
}
And Dockerfile:
FROM golang:1.11.4-alpine3.8
WORKDIR /go/src/server
COPY main.go main.go
CMD ["go", "run", "main.go"]
I build:
docker build -t goserver .
and run image:
docker run -p 1818:1818 goserver
At this moment server is running. When I hit Ctrl+C in my console container (and server process) is still running and the only way to stop is by calling docker to do it. I would like to know how to handle such behaviour so that server and container stops when hitting Ctrl+C.
Docker version 18.09.1