I am trying to run servers written in golang inside docker containers. For example:
package main
import "net/http"
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello"))
})
http.ListenAndServe(":3000", nil)
}
If I run this code on my local machine, I can send it a SIGINT
with <kbd>Ctrl-C</kbd> and it will close the application. When I run it inside a docker container, I can't seem to kill it with <kbd>Ctrl-C</kbd>.
# Dockerfile
FROM ubuntu:14.04
RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y golang
ENV GOPATH /go
COPY . /go/src/github.com/ehaydenr/simple_server
RUN cd /go/src/github.com/ehaydenr/simple_server && go install
CMD /go/bin/simple_server
I then proceeded to use docker to send signals to the container.
docker kill --signal=INT 9354f574afd4
Still running...
docker kill --signal=TERM 9354f574afd4
Still running...
docker kill --signal=KILL 9354f574afd4
Finally dead.
I'm not catching any signals in my code and ignoring them. I've even tried augmented the code above to catch signals and print them out (which works on my host, but when in the container, it's as if the signals never got to the program).
Has anyone experienced this before? I haven't tried something like this in another language, but I able to kill servers (e.g. mongo
, nginx
) using <kbd>Ctrl-C</kbd> while they're in a docker container.. Why isn't Go be getting the signals?
Not sure if this makes a difference, but I am on OSX and using docker-machine.
Any help is much appreciated.