Home‎ > ‎CIS 192‎ > ‎

Docker Compose

In this lesson you'll create a simple web application from scratch and "containerize" it. Lecture slides are here.


  • docker-compose


  • docker-compose.yaml

Further Reading

  • https://docs.docker.com/compose/


Last week you used a Dockerfile to create a container instance. Your container ran a single, simple web application. Most web applications, however, require you to have multiple different services. In the Docker world each services belongs in its own container. Docker Compose is an easy way to specify multiple, interlinked, containers and start them all at once. Docker Compose makes it possible to bundle an entire web application into a single file describing how to build the application. 


Docker Compose is still very new. To install it you should get the latest bleeding-edge version from GitHub:

The page has instructions for downloading and installing the Docker Compose executable. The installation is as simple as moving the executable to a directory in your path. This is decidedly not the best way to install software but... 

Composing a Cluster

Compose uses a YAML file to describe your application. Start by creating a directory for your composed application:

app-server$ mkdir ~/Wordpress
app-server$ cd ~/Wordpress

Now create a file called docker-compose.yaml in that directory and paste the following contents into it: 

version: '2'

     image: mysql:5.7
       - db_data:/var/lib/mysql
     restart: always
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

       - db
     image: wordpress:latest
       - "8000:80"
     restart: always
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress

Save the file and run the following command.

app-server$ docker-compose up 

Wait for the downloads to complete and you now have a Wordpress blog.