DEV Community

Russell Jones
Russell Jones

Posted on • Originally published at Medium on

Whalebrew

Docker Images as ‘Native’ Commands

Ahnee! If you’re from the Mac World you’ve probably used, or at least heard of, Homebrew. For the uninformed, Homebrew is The missing package manager for macOS. Or more accurately it’s a package management system for macOS that’s comparable to Redhat’s RPM, Debian’s APT, and Window’s Chocolatey.

Package managers make installing software easy by automagically fetching a pre-compiled binary and its dependencies, then copying them into your $PATH.

Depending on the software, compiling from source code is often difficult and time-consuming. Package managers let you get on with the using the software.

Installing With APT

figlet displays large characters made up of ordinary screen characters

I’ll demonstrate installing a package with APT in Ubuntu 18.10:

**$** sudo apt install figlet
Enter fullscreen mode Exit fullscreen mode

As you can see in the screenshot, APT downloads the figlet package (figlet_2.2.5–3_amd64.deb), unpacks it, then finally installs to /usr/bin/figlet.

**$** figlet "p4ck4g3's 4 l1fe\!"
Enter fullscreen mode Exit fullscreen mode

figlet in action

I Whale Always Love You

Whalebrew is an inevitable side effect of container proliferation. Their ease of use, speed, and low resource consumption make them ideal vehicles for single command or function execution.

As I’ve previously written, containers can be started, perform a task, then stopped in a matter of milliseconds. And that’s exactly what Whalebrew allows you to do in the form of Docker images aliased in your $PATH.

Now let’s put a magnifying glass up to Whalebrew by walking through its installation then “install a package”.

Whalebrew Demonstration

By creating an alias for running a Docker container and storing it in $PATH, running a command within a container is seamless and virtually indistinguishable from running a command directly in the environment.

What does that look like exactly? Assuming you already have Docker installed, we’ll start by installing Whalebrew (from https://github.com/bfirsh/whalebrew):

**$** sudo curl -L "https://github.com/bfirsh/whalebrew/releases/download/0.1.0/whalebrew-$(uname -s)-$(uname -m)" -o /usr/local/bin/whalebrew; sudo chmod +x /usr/local/bin/whalebrew
Enter fullscreen mode Exit fullscreen mode

Whalebrew installed to /usr/local/bin/whalebrew

Now let’s install figlet again, but this time with Whalebrew:

**$** sudo whalebrew install whalebrew/figlet
Enter fullscreen mode Exit fullscreen mode

whalebrew/figlet installed to /usr/local/bin/figlet

Now let’s run figlet again and adore the glorious results (We’ll use the full path in case the APT figlet is first in $PATH):

**$** /usr/local/bin/figlet "It's a whale of a time\!"
Enter fullscreen mode Exit fullscreen mode

figlet as run in a Docker container

Tada! We’ve just run figlet from within a container. You may have noticed it took a bit longer to execute, depending on your computer’s runtime juice.

So what just happened? Before we wrap it up we’ll take a quick look under the hood and examine the difference between running a native binary and a Whalebrew command.

Native vs. ‘Native’

Facsimile of an Indian Painting

Maazhichige, wrong ‘native’! The figlet program installed with APT is an ELF executable, the source code compiled from C, and it runs directly on your system.

The Whalebrew alias looks like this:

**$** cat /usr/local/bin/figlet
Enter fullscreen mode Exit fullscreen mode

When a package is executed, Whalebrew will run the specified image with Docker, mount the current working directory in /workdir, and pass through all of the arguments.

And this is essentially what Whalebrew executes:

**$** docker run -it -v "$(pwd)":/workdir -w /workdir whalebrew/figlet "It's a whale of a time\!"
Enter fullscreen mode Exit fullscreen mode

And well, that’s it, move along. Baamaapii.

Top comments (0)