dockrun oneshot — quick local environments for testing infrastructure

Since I work among a ton of different Linux distros and environments in my day-to-day work, I have a lot of tooling set up that's mostly-OS-agnostic. I found myself in need of a quick barebones CentOS 7 VM to play around in or troubleshoot an issue. Or I needed to run Ubuntu 16.04 and Ubuntu 14.04 side by side and run the same command in each, checking for differences. Or I needed to bring up Fedora. Or Debian.

I used to use my Vagrant boxes for VirtualBox to boot a full VM, then vagrant ssh in. But that took at least 15-20 seconds—assuming I already had the box downloaded on my computer!

When Docker came around a few years back, it was much faster to bring up an environment, but I couldn't do all the things I could do inside a VM to debug things like initv scripts or systemd configuration and logging. But as time went on, and I kept using and abusing Docker containers, I worked around those issues and produced a set of Docker images—one for each OS I use often—which included the default process manager and Ansible (since I run automation integration tests in these containers).

Taking that a step further, I thought it would be nice to have a quick command I could use to say "boot me a clean OS environment really quick", and thus my little bash function dockrun was born:

# Super useful Docker container oneshots.
# Usage: dockrun, or dockrun [centos7|fedora24|debian8|ubuntu1404|etc.]
dockrun() {
  docker run -it geerlingguy/docker-"${1:-ubuntu1604}"-ansible /bin/bash

The official list of OSes I currently maintain with a minimal install + process manager + Ansible include:

So if you want a quick CentOS 7 environment, if you stick the function above into your profile (see my dotfiles for an example) and source it, then run dockrun centos7 and within a second or two you'll be dropped into the command line as root on a CentOS 7 minimal install!

Dockrun - quick Docker environments

I'm sure other people do something similar; I just wanted to post this here in case you are like me and need a variety of OSes instantly spawnable, with the same baseline (and maybe even Ansible, since it's awesome for automation. (And hey, I wrote a book on that!)


Very Nice! Thanks for creating these images and the helper command, it's those little efficiency gains that all add up and create those great days of flow!

I ported your command to Fish shell.

function docrun
    if count $argv > /dev/null
               docker run --interactive --tty geerlingguy/docker-$argv[1]-ansible /bin/bash
               echo "Need to specify a Docker image, find a name here >"

funcsave docrun