Comment on Best way to dockerize a static website?
arran4@aussie.zone 8 months ago
The busybox one seems great as it comes with shells. php looks like it would add some issues.
Personally since I use go, I would create a go embedded app, which I would make a deb, rpm, and a dockerfile using “goreleaser”
package main import ( "embed" "net/http" ) //go:embed static/* var content embed.FS func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // Serve index.html as the default page http.ServeContent(w, r, "index.html", nil, content) }) // Serve static files http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(content)))) // Start the server http.ListenAndServe(":8080", nil) }
Would be all the code but allows for expansion later. However the image goreleaser builds doesn’t come with busybox on it so you can’t docker exec
into it. goreleaser.com/customization/docker/
sudneo@lemmy.world 8 months ago
I would consider the lack of a shell a benefit in this scenario. You really don’t want the extra attack surface and tooling.
Considering you also manage the host, if you want to see what’s going on inside the container (which for such a simple image can be done once while building it the first time more likely), you can use unshare to spawn a bash process in the container namespaces (e.g., unshare -m -p […] -t PID bash, or something like this - I am going by memory).