2015-06-07 22:59:58 +02:00
<!-- [metadata]>
+++
2015-09-16 17:01:43 +02:00
title = "Quickstart Guide: Compose and WordPress"
description = "Getting started with Compose and WordPress"
2015-06-07 22:59:58 +02:00
keywords = ["documentation, docs, docker, compose, orchestration, containers"]
[menu.main]
parent="smn_workw_compose"
weight=6
+++
<![end-metadata]-->
2014-01-27 22:43:22 +01:00
2015-06-07 22:59:58 +02:00
2015-09-16 17:01:43 +02:00
# Quickstart Guide: Compose and WordPress
2014-01-27 22:43:22 +01:00
2015-09-16 17:01:43 +02:00
You can use Compose to easily run WordPress in an isolated environment built
2015-08-24 21:25:25 +02:00
with Docker containers.
2015-02-27 03:58:06 +01:00
2015-06-07 22:59:58 +02:00
## Define the project
2015-02-27 03:58:06 +01:00
2015-09-16 17:01:43 +02:00
First, [Install Compose ](install.md ) and then download WordPress into the
2015-02-27 03:58:06 +01:00
current directory:
2014-01-27 22:43:22 +01:00
2014-10-24 23:50:06 +02:00
$ curl https://wordpress.org/latest.tar.gz | tar -xvzf -
2014-01-27 22:43:22 +01:00
2015-02-27 03:58:06 +01:00
This will create a directory called `wordpress` . If you wish, you can rename it
to the name of your project.
Next, inside that directory, create a `Dockerfile` , a file that defines what
environment your app is going to run in. For more information on how to write
Dockerfiles, see the
[Docker user guide ](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile ) and the
[Dockerfile reference ](http://docs.docker.com/reference/builder/ ). In this case,
your Dockerfile should be:
2014-01-27 22:43:22 +01:00
2015-06-21 21:37:20 +02:00
FROM orchardup/php5
ADD . /code
2014-01-27 22:43:22 +01:00
2015-02-27 03:58:06 +01:00
This tells Docker how to build an image defining a container that contains PHP
2015-09-16 17:01:43 +02:00
and WordPress.
2014-01-28 13:45:03 +01:00
2015-02-27 03:58:06 +01:00
Next you'll create a `docker-compose.yml` file that will start your web service
and a separate MySQL instance:
2014-01-27 22:43:22 +01:00
2015-06-21 21:37:20 +02:00
web:
build: .
command: php -S 0.0.0.0:8000 -t /code
ports:
- "8000:8000"
links:
- db
volumes:
- .:/code
db:
image: orchardup/mysql
environment:
MYSQL_DATABASE: wordpress
2014-01-27 22:43:22 +01:00
2015-10-06 17:37:36 +02:00
A supporting file is needed to get this working. `wp-config.php` is
2015-09-16 17:01:43 +02:00
the standard WordPress config file with a single change to point the database
2015-02-27 03:58:06 +01:00
configuration at the `db` container:
2014-01-27 22:43:22 +01:00
2015-06-21 21:37:20 +02:00
< ?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', "db:3306");
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
$table_prefix = 'wp_';
define('WPLANG', '');
define('WP_DEBUG', false);
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
2014-01-27 22:43:22 +01:00
2015-02-27 03:58:06 +01:00
### Build the project
2014-01-27 22:43:22 +01:00
2015-09-16 17:01:43 +02:00
With those four files in place, run `docker-compose up` inside your WordPress
2015-02-27 03:58:06 +01:00
directory and it'll pull and build the needed images, and then start the web and
2015-08-24 21:25:25 +02:00
database containers. If you're using [Docker Machine ](https://docs.docker.com/machine ), then `docker-machine ip MACHINE_VM` gives you the machine address and you can open `http://MACHINE_VM_IP:8000` in a browser.
2015-02-25 09:43:33 +01:00
2015-02-27 03:58:06 +01:00
## More Compose documentation
2015-02-25 09:43:33 +01:00
2015-06-16 05:52:55 +02:00
- [User guide ](/ )
2015-05-12 13:44:43 +02:00
- [Installing Compose ](install.md )
- [Get started with Django ](django.md )
- [Get started with Rails ](rails.md )
2015-09-16 17:01:43 +02:00
- [Get started with WordPress ](wordpress.md )
2015-08-11 18:38:49 +02:00
- [Command line reference ](/reference )
2015-02-25 09:43:33 +01:00
- [Yaml file reference ](yml.md )