Whalebrew
Tags: docker
Published: 2020-02-19 03:43:57

---
title: Whalebrew
published: true
date: 2018-10-25 07:26:07 UTC
tags: docker
canonical_url: https://medium.com/@jonesrussell42/whalebrew-9c3535b3c722
---

#### Docker Images as ‘Native’ Commands

Ahnee! If you’re from the Mac World you’ve probably used, or at least heard of, [Homebrew](https://brew.sh/). 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](http://rpm.org/), Debian’s [APT](https://wiki.debian.org/Apt), and Window’s [Chocolatey](https://chocolatey.org/).

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

![](https://cdn-images-1.medium.com/max/734/1*MLwvtPEG0yoOEtCzml-R9Q.png)<figcaption>figlet displays large characters made up of ordinary screen characters</figcaption>

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

```
**$** sudo apt install figlet
```

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\!"
```

![](https://cdn-images-1.medium.com/max/734/1*XkvZZOmATGe8p6Ri2ZqOaA.png)<figcaption>figlet in action</figcaption>

### 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](https://medium.com/@jonesrussell42/docker-for-legacy-drupal-development-6df4dec8b309#b965), 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](https://medium.com/@jonesrussell42/docker-for-legacy-drupal-development-6df4dec8b309#db40), we’ll start by installing Whalebrew (from [https://github.com/bfirsh/whalebrew](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
```

![](https://cdn-images-1.medium.com/max/734/1*EzjhwX8SPJ-Zlcjxiayt2A.png)<figcaption>Whalebrew installed to /usr/local/bin/whalebrew</figcaption>

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

```
**$** sudo whalebrew install whalebrew/figlet
```

![](https://cdn-images-1.medium.com/max/734/1*bLCbFgBYsdCcLfeKnr2UpA.png)<figcaption>whalebrew/figlet installed to /usr/local/bin/figlet</figcaption>

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\!"
```

![](https://cdn-images-1.medium.com/max/734/1*X8Eew1wrMcMjbw2-skNPGQ.png)<figcaption>figlet as run in a Docker container</figcaption>

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’

![](https://cdn-images-1.medium.com/max/799/1*zpAHqMDHdy4hqXN3fo1hAQ.jpeg)<figcaption><a href="http://bibliodyssey.blogspot.com/2006/08/bodmer-series-on-native-america.html">Facsimile of an Indian Painting</a></figcaption>

Maazhichige, wrong ‘native’! The figlet program installed with APT is an ELF executable, the [source code](https://github.com/cmatsuoka/figlet) compiled from C, and it runs directly on your system.

The Whalebrew alias looks like this:

```
**$** cat /usr/local/bin/figlet
```

![](https://cdn-images-1.medium.com/max/734/1*zMYeFQLlnwjjhttXCnVGiw.png)

> 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\!"
```

![](https://cdn-images-1.medium.com/max/734/1*lSmdCGIGlEE6KDWGBHfFMA.png)

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