├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── http.go └── whoami@.service /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:alpine3.6 AS binary 2 | ADD . /app 3 | WORKDIR /app 4 | RUN go build -o http 5 | 6 | FROM alpine:3.6 7 | WORKDIR /app 8 | ENV PORT 8000 9 | EXPOSE 8000 10 | COPY --from=binary /app/http /app 11 | CMD ["/app/http"] 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jason Wilder 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | whoami 2 | ====== 3 | 4 | Simple HTTP docker service that prints it's container ID 5 | 6 | $ docker run -d -p 8000:8000 --name whoami -t jwilder/whoami 7 | 736ab83847bb12dddd8b09969433f3a02d64d5b0be48f7a5c59a594e3a6a3541 8 | 9 | $ curl $(hostname --all-ip-addresses | awk '{print $1}'):8000 10 | I'm 736ab83847bb 11 | -------------------------------------------------------------------------------- /http.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | "net/http" 7 | "log" 8 | ) 9 | 10 | func main() { 11 | port := os.Getenv("PORT") 12 | if port == "" { 13 | port = "8080" 14 | } 15 | 16 | fmt.Fprintf(os.Stdout, "Listening on :%s\n", port) 17 | hostname, _ := os.Hostname() 18 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 19 | fmt.Fprintf(os.Stdout, "I'm %s\n", hostname) 20 | fmt.Fprintf(w, "I'm %s\n", hostname) 21 | }) 22 | 23 | 24 | log.Fatal(http.ListenAndServe(":" + port, nil)) 25 | } 26 | 27 | -------------------------------------------------------------------------------- /whoami@.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=whoami-%i 3 | After=docker.service 4 | 5 | [Service] 6 | TimeoutStartSec=0 7 | ExecStartPre=-/usr/bin/docker kill whoami-%i 8 | ExecStartPre=-/usr/bin/docker rm whoami-%i 9 | ExecStartPre=/usr/bin/docker pull jwilder/whoami 10 | ExecStart=/usr/bin/docker run --name whoami-%i -p :8000 jwilder/whoami 11 | ExecStop=/usr/bin/docker stop whoami-%i 12 | --------------------------------------------------------------------------------