For a while, and purely for fun and experimentation, I’ve wanted to create a Docker image that does something useful and isn’t huge. I knew that it was possible to use gcc to compile C code with the
-static flag and then run it standalone inside a Docker container, but I’d never actually tried it. It’s just one of those things I wanted to do. It means you can build your Docker image from scratch and not need any other OS files from another distribution. I was aiming for something that could be measured in kilobytes rather than megabytes.
So … I decided to try and build my mini-webserver, dweb with the
-static flag, then pack it down with upx before setting it up to run in Docker. I thought that I could get it to run the webserver in the container, but serve up files from a location on the host machine. I have no real need to do that, but I thought that it would be interesting. I’m not suggesting that this is a really good idea, but I do like the idea of avoiding bloat in docker images.
The result is on Docker Hub here and GitHub here. The compressed size of the image comes in at just 364 KB. That makes a nice change.
Well, that was fun. Perhaps one day I’ll use this technique to do something useful, but at least I know how.