July 2, 2016

Setting up Docker the "easy" way on Mac or Windows: The Docker Toolbox and the Get Started Guide

Toolbox installer
It's the Docker Toolbox for Easy Installation!

I've been on a quest since I became an automation developer, documenting everything I have been doing adding to the automated test framework at my workplace. Because I didn't start at square one, there are things I wonder about...

The Past: Browser images on Virtual Machines


When performing browser testing around a decade ago, I used to use VMWare to setup numerous virtual machine images for my testing team. The images contained the multitude of browsers and platforms configurations we needed. I would configure and place them the shared drive at whatever company I was working on. If we wanted to see how our web application looked on a clean install of the now defunct Netscape Navigator and Windows NT, and compare that with IE6, IE7, and IE8, our entire testing team could blow away whatever previous virtual machines they had on their desktop, and copy whatever was needed that day to their computer.

I am on a quest to find that type of ease-of-use.




The Future: Browser images in Containers


Although I haven't documented it in my blog, yet, it is easy to find tutorials to download and install Selenium Grid, which provides a small sample of browsers you can hook up your automated test framework to. My goal is to place my Selenium Grid in a Docker container, so that when automated testers are running automated tests on their local machine, they can set up the Docker image and have every browser and platform they need at their fingertips.

A few months ago, we explored how to set up a virtual machine with VirtualBox, Vagrant, and Docker. It would have been much too complex for someone just switching from manual testing to automated testing! Where could we find an easier way for someone to be able to dive in and set things up?

We are going to be exploring the Docker Toolbox, a tool I heard about as I was listening to a video lecture at Selenium Conf 2016.

What Is a Docker Container?

"A container is an entire portable runtime environment: an application, plus all its dependencies, libraries and other binaries, and configuration files needed to run it, bundled into one package. By containerizing the application platform and its dependencies ,all differences in OS distributions and underlying infrastructure are abstracted away which makes it easy to share and execute anywhere".
-- Irfan Ahmad, Testing as a Container: Using Docker with selenium and friends to ship fast

And What Is Docker, Again?


Docker was created by Solomon Hykes while he was working at a company he founded, dotCloud. Docker was first released back in March 2013, written in the Google invented language called Go.

The article What is Docker? on Docker's official site mentions that "Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment".

And What is a Container?


Containers are lightweight: "Containers running on a single machine share the same operating system kernel; they start instantly and use less RAM. Images are constructed from layered filesystems and share common files, making disk usage and image downloads much more efficient".

Containers are smaller than virtual machines: VMs "include the application, the necessary binaries and libraries, and an entire guest operating system -- all of which can amount to tens of" gigabytes. Containers "include the application and all of its dependencies --but share the kernel with other containers, running as isolated processes in user space on the host operating system. Docker containers are not tied to any specific infrastructure: they run on any computer, on any infrastructure, and in any cloud".

And, yes, Docker has a GitHub sitehttps://github.com/docker/docker
"Docker containers are both hardware-agnostic and platform-agnostic. This means they can run anywhere, from your laptop to the largest cloud compute instance and everything in between - and they don't require you to use a particular language, framework or packaging system. That makes them great building blocks for deploying and scaling web apps, databases, and backend services without depending on a particular stack or provider.

"Docker began as an open-source implementation of the deployment engine which powered dotCloud, a popular Platform-as-a-Service. It benefits directly from the experience accumulated over several years of large-scale operation and support of hundreds of thousands of applications and databases".

The Docker Toolbox

According to the Docker Toolbox Overview, the Docker Toolbox contains:
  • Docker Machine for running docker-machine commands
  • Docker Engine for running the docker commands
  • Docker Compose for running the docker-compose commands
  • Kitematic, the Docker GUI
  • a shell preconfigured for a Docker command-line environment
  • Oracle VirtualBox

... There is a GUI? Awesome! Don't tell anyone, but I really hate using the command line. It reminds me of working in a musty basement Mainframe computer lab during my undergrad program. Windows was a gigantic step towards the great user interface that Apple already had stolen from Xerox years before.

You can go to https://www.docker.com/products/docker-toolbox to download the Docker Toolbox for the Mac or the PC. For the PC it downloads a simple executable file you can run.

You can even go to the Docker Toolbox GitHub site to see what is happening behind-the-scenes.

Installing Docker Toolbox


Okay... that's weird... I downloaded the tool, ran the executable, and as I was going through the installation process I saw an option that could be chosen during the installation:

  • Install VirtualBox with NDIS5 driver [default NDIS6]. 

What the what? For a a tool that is supposed to be easy, there needs to be a bit more user prompts to help a user to make a decision.

After a bit of searching I found on VirtualBox's documentation: ""The user is able to choose between NDIS5 and NDIS6 host network filters drivers during the installation. This is realized via a command line parameter NETWORKTYPE. The NDIS6 driver is default for Windows Vista and later. For older Windows versions, the installer will automatically select the NDIS5 driver and this cannot be changed. For Windows Vista and later the user can force to install the (legacy) NDIS5 host network filter driver using NETWORKTYPE=NDIS5".

I'm going to leave that checkbox unchecked. I don't think I am going to need Windows 95, Win98, WinNT, or Windows ME. In case I do, I can set the parameters through the command line I can use either/ or:




  • VirtualBox.exe -msiparams NETWORKTYPE=NDIS5
  • msiexec /i VirtualBox-<version>-MultiArch_<x86|amd64>.msi NETWORKTYPE=NDIS5

  • At the end of the process -- which seems to involve my copy of Git-SCM being uninstalled (Huh?) -- I have two icons in a folder: Docker Quickstart Terminal and Kitematic.


    Let's see what these buttons do: After double-clicking on the Docker Quickstart Terminal, five minutes later a terminal window appears:



    • Hrm. That isn't too helpful. Let's type in exit to close the window. 
    • When I start Kitematic, it says: "Error: getaddrinfo ENOTFOUND docker.local docker.local:2375". So far, this doesn't seem too much easier than working with the command line. 
    Sidenote: MinGW stands for Minimalist GNU for Windows, whose home was at http://www.mingw.org/. Writing Windows apps? MinGW was a bare-bones Open Source programming toolset porting ObjectiveC to Windows back in 2005, and recreated by OneVision Software.

    To the documentation!

    Get Started With Docker

    The Get Started With Docker guide is at https://docs.docker.com/engine/getstarted/


    "This tutorial is designed as a getting started with Docker, and works the same whether you are using Docker for Mac, Docker for Windows, Docker on Linux, or Docker Toolbox (for older Mac and Windows systems).

    "If you are using Docker Toolbox, you can use the Docker Quickstart Terminal to run Docker commands in a pre-configured environment instead of opening a command line terminal".

    Step One: Installing Docker


    According to Step One, after the Docker QuickStart terminal starts, we can type in the command:
    $ docker run hello-world


    "Hello from Docker.
    "This message shows that your installation appears to be working correctly.

    "To generate this message, Docker took the following steps:
    "1. The Docker Engine CLI client contacted the Docker Engine daemon.
    "2. The Docker Engine daemon pulled the "hello-world" image from the Docker Hub.
    "3. The Docker Engine daemon created a new container from that image which runs the
       executable that produces the output you are currently reading.
    "4. The Docker Engine daemon streamed that output to the Docker Engine CLI client, which sent it
       to your terminal.

    "To try something more ambitious, you can run an Ubuntu container with:
    "$ docker run -it ubuntu bash

    "Share images, automate workflows, and more with a free Docker Hub account: https://hub.docker.com

    "For more examples and ideas, visit: https://docs.docker.com/userguide/"

    ... Thank you for the tips, Docker!

    Let's see... If I want to see all the Docker images on my machine:
    $ docker ps -a

    • Image: hello-world Names: sleepy-austin
    • Image kitematic/hello-world-nginx: latest (Lists ports) Names: hello-world-nginx

    Step Two: Running Docker Images in Docker Engine


    Step Two of the users guide talks about how we ran in the terminal the command:

    • docker run hello-world

    Remember, a Docker image is the entire filesystem and parameters we use at runtime. The container runs the instance of the image.

    When we ran "hello-world" the Docker Engine started and ran a Docker container, and attempted to run the hello-world image. Since we didn't have an image, it connected to the Docker Hub ( https://hub.docker.com ) and downloaded that image to the container.

    Since I eventually want to put Selenium Grid in a container, I might as well sign up for an account. It's free! ... Now I have a Docker Hub account to add to my collection!



    "A Docker image, though, is capable of much more. An image can start software as complex as a database, wait for you (or someone else) to add data, store the data for later use, and then wait for the next person".

    Step Three: Searching Docker Hub for Docker Images

    Cowsay was a Perl program written by Tony Monroe back in 1999 ( according to Wikipedia ). You could type in:

     $ cowsay moo 
    

    and see:
    Linux command: $ cowsay moo

    With Step Three of the Docker Get Started guide we:

    • Go to the Docker Hubhttps://hub.docker.com
    • Search for the keyword: "whalesay" to search for that Docker image
    • Select docker/ whalesay.
    Selecting on the image, we are brought to the docker / whalesay repository at https://hub.docker.com/r/docker/whalesay/.

    There, in plain English, are the instructions on how to use the Docker image:

     $ docker run docker/whalesay cowsay boo  
    

    Typing this into the Docker Quickstart Terminal at the command prompt, it starts downloading, extracting, and installing the Docker Image on your machine. In the end, you see...


    Hrm... I wonder what else I can get the whale to say? 

    You heard the whale! :) You gotta do it, now
    You can see in the Docker Hub, it even shows for https://hub.docker.com/r/docker/whalesay/ the Dockerfile which sets everything up. The Dockerfile runs the following Unix commands:

     apt-get update   
     apt-get install -y cowsay --no-install-recommends   
     rm -rf /var/lib/apt/lists/* \  
     mv /usr/share/cowsay/cows/default.cow /usr/share/cowsay/cows/orig-default.cow  
     # "cowsay" installs to /usr/games  
     ENV PATH $PATH:/usr/games  
     COPY docker.cow /usr/share/cowsay/cows/  
     RUN ln -sv /usr/share/cowsay/cows/docker.cow /usr/share/cowsay/cows/default.cow  
     CMD ["cowsay"]  
    

    What the heck is APT-GET?

    ""The apt-get utility is a powerful and free package management command line program, that is used to work with Ubuntu’s APT (Advanced Packaging Tool) library to perform installation of new software packages, removing existing software packages, upgrading of existing software packages and even used to upgrading the entire operating system". - Useful Commands of APT-GET

    Now, if you run at the command prompt: $ docker images you can see that docker/ whalesay is now included.

    And, yes, with the Quickstart terminal, you can run Unix on your Windows machine.




    Step Four: Build Your Own Docker Image

    Step Four walks you through how to make a new Unix directory, change into the directory, use the touch command to create a file, list the items in the directory, and edit commands.


    Happy Testing!

    -T.J. Maher
    Sr. QA Engineer,
    Fitbit-Boston

    // QA Engineer since Aug. 1996
    // Automation developer for [ 1.5 ] year and still counting!
    // Check us out on Facebook!