I’ve been playing with Docker a lot lately. Docker is a tool for creating lightweight virtual environments based on Linux containers. They are extremely useful for running services, but you can also use them for running one-off tasks that you don’t want to run on the host system directly. Since a container shares the host machine’s kernel, startup is instantaneous and there’s no extra memory footprint. Think of Linux containers as generalized chroot environments or as extremely lightweight virtual machines.
One nice use case I’ve come across recently was to convert images on the web to ASCII art using aalib. There are very nice Python bindings available for aalib, even though installing them would require installing 17 new packages on my desktop machine. With Docker, I can isolate all that in a dedicated environment that I can easily get rid off later.
I’ve put it up on Github so you can play with it:
$ git clone https://github.com/mafr/docker-aaconvert $ cd docker-aaconvert $ docker build -t aaconvert .
Note that depending on your setup, you may need root privileges. Once you’ve built the Docker image (as opposed to a JPEG image), you can run it using the following command:
$ docker run --rm aaconvert http://google.com/favicon.ico
Careful, though: "Containers do not contain". Don’t run random code you found on the Internet, the usual security rules still apply. Containers will protect you to some degree, but there are ways to break out of them.