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
In 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.
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:
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.
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.
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.
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”.
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.
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
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
- New to Docker? Try our 10 min online tutorial
- Share images, automate builds, and more with a free Docker Hub account
- Read the Docker 1.9 Release Notes
- Subscribe to Docker Weekly
- Register for upcoming Docker Online Meetups
- Attend upcoming Docker Meetups
- Register for DockerCon 2015 Europe
- Start contributing to Docker