Docker ComposeΒΆ

We will run the same previous application of wordpress and MySQL linking in this tutorial but with Docker compose which was launched recently and is a tool use to define and run complex linked applications with docker. With docker compose we can define the entire multi-container application in single file and then the application can be spinned up using one command.

Create a new project folder

$ mkdir dockercompose
$ cd dockercompose

Create Docker compose file

Create docker-compose.yml with preferred editor having the following contents

web:
    image: wordpress
    links:
     - mysql
    environment:
     - WORDPRESS_DB_PASSWORD=sample
    ports:
     - "127.0.0.3:8080:80"
mysql:
image: mysql:latest
environment:
 - MYSQL_ROOT_PASSWORD=sample
 - MYSQL_DATABASE=wordpress

Get the linked containers up

$ docker-compose up
Creating dockercompose_mysql...
Creating dockercompose_web...
Attaching to dockercompose_mysql, dockercompose_web
mysql | Initializing database
..............

Visit the IP address http://127.0.0.3:8080 in order to see the setup page of the newly created linked wordpress container.