2015-06-07 22:59:58 +02:00
<!-- [metadata]>
+++
2016-01-24 21:03:44 +01:00
title = "Quickstart: Compose and WordPress"
2015-09-16 17:01:43 +02:00
description = "Getting started with Compose and WordPress"
2015-06-07 22:59:58 +02:00
keywords = ["documentation, docs, docker, compose, orchestration, containers"]
[menu.main]
2016-01-24 21:03:44 +01:00
parent="workw_compose"
2015-06-07 22:59:58 +02:00
weight=6
+++
<![end-metadata]-->
2014-01-27 22:43:22 +01:00
2015-06-07 22:59:58 +02:00
2016-01-24 21:03:44 +01:00
# Quickstart: 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
2015-12-21 01:52:54 +01:00
[Docker user guide ](https://docs.docker.com/engine/userguide/dockerimages/#building-an-image-from-a-dockerfile ) and the
[Dockerfile reference ](https://docs.docker.com/engine/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
2016-02-16 22:38:31 +01:00
version: '2'
services:
web:
build: .
command: php -S 0.0.0.0:8000 -t /code
ports:
- "8000:8000"
depends_on:
- 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-12-21 01:52:54 +01: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-11-18 11:17:23 +01:00
- [User guide ](index.md )
2015-05-12 13:44:43 +02:00
- [Installing Compose ](install.md )
2015-10-09 16:49:41 +02:00
- [Getting Started ](gettingstarted.md )
2015-05-12 13:44:43 +02:00
- [Get started with Django ](django.md )
- [Get started with Rails ](rails.md )
2015-10-13 13:01:19 +02:00
- [Command line reference ](./reference/index.md )
2015-10-13 21:23:27 +02:00
- [Compose file reference ](compose-file.md )