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:

FROM ubuntu:14.04 MAINTAINER CenturyLink

# Install node & npm
RUN apt-get -qqy update && DEBIAN_FRONTEND=noninteractive apt-get -y install vim git nodejs npm RUN ln -s /usr/bin/nodejs /usr/bin/node
# Install Wetty
WORKDIR /opt/wetty RUN git clone https://github.com/krishnasrinivas/wetty.git . && git reset --hard 223b1b1 RUN npm install
# Set-up term user RUN useradd -d /home/term -m -s /bin/bash term RUN echo 'term:term' | chpasswd RUN sudo adduser term sudo
CMD env | grep -v 'HOME|PWD|PATH' | while read env; do echo "export $env" >> /home/term/.bashrc ; done && node /opt/wetty/app.js -p 3000

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.

Here is the OpenStack Dockerfile:

FROM centurylink/wetty-cli:0.0.8 # Install CLIs RUN apt-get update && apt-get install -y python-software-properties

RUN apt-get update && apt-get install -y python-keystoneclient && apt-get install -y python-swiftclient && apt-get install -y python-novaclient && apt-get install -y python-troveclient && apt-get install -y python-glanceclient && apt-get install -y python-cinderclient && apt-get install -y python-heatclient && apt-get install -y python-ceilometerclient && apt-get install -y python-neutronclient

And that's it!!! Your Dockerfile is done. Now use the docker build command to create the image locally:

$ docker build -t mystuff/openstackcli:latest .

Be sure to run this command within the same directory where your Dockerfile resides.

You now have an image with all the OpenStack CLIs installed. Next, create your container from the image, subbing in your own values:

$ docker run --rm --name openstack -p 8000:3000 -e "OS_AUTH_URL=xxxxxx" -e "OS_REGION_NAME=xxxxxx" -e "OS_TENANT_NAME=xxxxxx" -e "OS_USERNAME=xxxxxx" -e "OS_PASSWORD=xxxxxx" mystuff/openstackcli:latest

Browse to http://localhost:8000 (use VirtualBox port forwarding if on a Mac), login with term/term and behold the terminal in all its glory:

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.