Aanand Prasad

Getting Started with Docker Toolbox and Compose

Today at DockerCon EU 2015, I ran through a demo of running and developing an app from a fresh computer using Docker Toolbox and Compose. This was to show how easy it is for new developers to get started when you run your development environments with Docker.

The demo showed an app that has:

• A Python webapp which lets you vote between two options
• A Redis queue which collects new votes
• A Java worker which consumes votes and stores them in…
• …A Postgres database backed by a Docker volume
• A Node.js webapp which shows the results of the voting in real time

docker-toolboxIn the demo I created and ran the containers using Docker Compose, which installs as part of Docker Toolbox, and is now available for the first time on Windows. I then used Kitematic to examine the running app, and showed how I can quickly make changes to it.

Here are the steps to reproduce the demo:

To get started, first download and install Docker Toolbox.

The Toolbox installer will install VirtualBox, Docker Engine, Docker Machine, Docker Compose and Kitematic.

It will place two shortcuts on your desktop: Kitematic and Docker Quickstart Terminal.

Open Docker Quickstart Terminal. It will create and start a VirtualBox VM running Docker Engine, then configure the command-line environment so that you can talk to it. When it’s finished, you will see an ASCII-art whale and a command prompt.

image10

Run the following command and press Enter to download the source code for the demo app:

git clone https://github.com/docker/example-voting-app

Next, enter the directory where the app’s source code lives:

cd example-voting-app/voting-apps

Start the app with Docker Compose:

docker-compose --x-networking up

This will take some time. Docker Compose will pull all the images it needs from the Docker Hub, build the images for the voting app, results app and worker, create all five containers and finally stream their output to the terminal.

To see the containers running, open Kitematic. You should see the five containers running in the left-hand column.

image12

Click on voteapps_voting-app_1. Kitematic will show its logs, as well as a web preview.

Click the arrow button above the web preview to open the voting app in a browser.

image14

You’ll be able to vote for either cats or dogs. Cast your vote!

Next, return to Kitematic, click on voteapps_result-app_1, and open it in the browser just as you did with the voting app. You should see your vote reflected by a 100% turnout.

Now that the app is running, it’s worth having a look at the code. Navigate to the directory where the app lives (you’ll find it in your home directory under example-voting-app) and open docker-compose.yml. You’ll see that it defines five services, using either images straight from the Docker Hub or build directories containing Dockerfiles. You can also browse the code for the Python voting app, Java worker and Node.js results app.

Note that in docker-compose.yml, the voting-app and result-app services mount their code inside the containers as volumes. This makes it really easy to make incremental changes to those apps and see the results immediately when you refresh the browser.

image00

To try this out, open up app.py in the voting-app directory and change the voting candidates to something other than “Cats” and “Dogs” – for example, “Star Trek” and “Star Wars”.

image11image04

 

 

 

 

 

 

 

You can also make the same change in result-app, by editing index.html under views.

Save both files, then refresh both browser tabs. You’ll see that the apps have updated.

image06image09

 

 

 

 

 

 

 

 

There you have it: you’ve gone from zero to a live development environment, running a complex multi-container application using Python, Redis, Java, Postgres and Node.js without having to install any of them on your computer.

Stop the app

To shut the app down, go back to the Quickstart Terminal where you launched the app and press Ctrl-C to stop the containers. You can then either remove them one-by-one in Kitematic, or with a single command in the terminal:
docker-compose rm -f

Learn more

If you want to learn more about Docker Toolbox and Docker Compose, check out the Docker documentation. And if you need any help, you can post in our support forums, or post a question on StackOverflow.


 

Learn More about Docker

 

,

Aanand Prasad

Getting Started with Docker Toolbox and Compose


5 Responses to “Getting Started with Docker Toolbox and Compose”

  1. bdaniel7

    I’m trying to follow your tutorial but when I’m running
    C:\Users\me\example-voting-app\vote-apps (master)
    λ docker-compose up –x-networking up

    I’m getting just the help message:
    Builds, (re)creates, starts, and attaches to containers for a service….

    Reply
  2. Links i found interesting the last week! - Magnus Udbjørg

    […] Getting Started with Docker Toolbox and Compose […]

    Reply
  3. EvanZ

    `docker-compose –x-networking up` doesn’t work for me. I just get the same message as if I used `docker-compose -h`. Any idea what the issue might be?

    Reply
    • Martin

      Are you using an up-to-date version of Docker Compose?

      Reply
    • IT Rookie

      With the latest version of docker-compose networking is not experimental anymore…so the “–x-networking” option is no longer required. Just run “docker-compose up”

      Reply

Leave a Reply

Get the Latest Docker News by Email

Docker Weekly is a newsletter with the latest content on Docker and the agenda for the upcoming weeks.