Using Wetty to Create Docker Containers for CLIs

Pat Cox

September 25, 2014

What if your multi-container Docker application needs a CLI? You might think you are stuck with installing it directly on your CoreOS host.

But, you can actually create a tunnel to allow your CLI to access your application from your laptop.

By shipping your application with Wetty, a terminal emulator, not only can you have a simple way to interact with your application but you'll also be able to control versioning of the CLIs and make sure they match the services you and your template consumers have running in your application.

Get Wetty

Cue Wetty from Krishna Srinivas, a terminal in a web browser accessed over http/https. Wetty has significant improvements over other terminal emulators by using web sockets instead of ajax and takes advantage of ChromeOS' terminal emulator, hterm, giving you, well, a full featured terminal emulator.

Krishna has also release a dockerized version of Wetty - krishnasrinivas/wetty. Now that Wetty is containerized, you can use it in Panamax and include it on a template! We at CenturyLink have created a Wetty image just for that purpose -- to install CLIs on a docker image that can be included in your template. Read on!

Creating your own CLI Docker Image

CenturyLink Wetty base image

For our example, we will use centurylink/wetty-cli. This particular image is based on Krishna's original image, but designed to be used as the base image for adding your CLI or headless app. This image is not intended for use on its own, but via the Docker FROM command within your own Dockerfile. Before we start stitching together our application, let's better understand all the factors at play. Here is the Wetty image Dockerfile:

Note that the username and password for Wetty are set asterm and the exposed port is 3000.

Add Your Stuff!

As a simple working example, let's use OpenStack and its bevy of CLI tools. OpenStack has several CLIs, one for every service, and in this example you'll create a container with each CLI accessible and have the ability to run that container from Panamax. By referencing the centurylink/wetty-cli image with the Docker FROM command, all you need to do is add the prerequisites and packages for your CLI installation; everything else is taken care by the parent Wetty image.

But wait, wait... there must be an easier way than typing all those environmental variables each time -- something repeatable, shareable, beautiful. Read on!

Running in Panamax

Let's assume you have an image created and made available on the Docker Registry. We can now create a template in Panamax and use its GUI to add values we would typically manipulate during a docker run.

Set Environment Vars

To get the most out of your OpenStack CLI image, you need to provide environmental variables during the container creation. Without this, you would have to add them manually after the container has run in the Wetty terminal itself -- no fun! Panamax allows you to collect those values and save them to a template, ensuring your application will run with the same environmental variables each and every time.

After searching for and launching your Docker OpenStack CLI image within Panamax, browse to the details of the service. Here you will be able to enter the values needed to run the container that you had to manually specify in your docker run command.

This would be a good time to save your template to a GitHub repository so you can use it later and so that other Panamax users can kick the tires of your application. However, before saving remember that you wouldn't want to actually add the environmental variable values at this time (i.e. your OpenStack creds) as this would be saved to your template and could be exposed to the public. For authentication, it's better to run the template and then add those values in the GUI directly.

Now that you have saved this as a template, you can reuse the template over and over again, providing your creds to access your OpenStack resources directly in the GUI. After those values are entered and you Save Changes, wait for the application to restart and then browse to http://localhost:8000 (use VirtualBox port forwarding if on a Mac). Login with term/term and BAM!

More Use Cases

This example focused on a standalone, single image CLI. The real power comes from adding a Wetty-based CLI image to compliment any application where a CLI is utilized.

For example, you can add a Drush Wetty image to a Drupal application allowing you to include the CLI with the application that leverages it. Use the power of Panamax to setup linking between your containers and leverage the environmental variables available to you from Docker itself. You can then comfortably use the tools from your local machine's browser -- no fussing around with extra installs or configurations -- accessing the CLI directly in the environment where your application resides!

Perhaps you have monitoring tools or utilities you would like to leverage directly in the container environment; Wetty gives you that ability. Furthermore, by creating a Wetty-based image and including it in your template, you can control the versioning around the CLI and the application, meaning no more issues where your CLI is out of sync with the rest of the app!

Other Examples

You can find these Wetty-based images and templates available to you in Panamax right now.