Sign inSign up

reeganexe/small-http

By reeganexe

Updated over 3 years ago

Smallest simple HTTP server.

Image
0

428

reeganexe/small-http repository overview

A very minimal simple HTTP test image

Just 4.08 MB compressed image.

docker run -p 8080:8080 reeganexe/small-http
  • arm64 - 3.81MB
  • amd64 - 4.08MB
Code
package main

import (
  "fmt"
  "io"
  "log"
  "net/http"
  "os"
  "time"
)

func main() {
  http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
    resp, err := http.Get("https://go.dev/favicon.ico")
    if err != nil {
      w.WriteHeader(404)
      return
    }
    defer resp.Body.Close()
    w.Header().Add("Cache-Control", "max-age=604800")
    io.Copy(w, resp.Body)
  })

  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    hostname, err := os.Hostname()
    if err != nil {
      panic(err)
    }

    fmt.Fprintf(w, "Hello from host: %q The current  time is %q", hostname, time.Now().String())
  })

  log.Fatal(http.ListenAndServe(":8080", nil))
}
Dockerfile
FROM golang:1.20 as build
WORKDIR /app
COPY go.mod *.go ./
RUN CGO_ENABLED=0 go build -o small-http 

FROM scratch
WORKDIR /app
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /app/small-http /app/

CMD ["./small-http"]

Tag summary

Content type

Image

Digest

sha256:a6ddb495d

Size

3.8 MB

Last updated

over 3 years ago

docker pull reeganexe/small-http