2015-02-27 03:58:06 +01:00
|
|
|
page_title: Quickstart Guide: Compose and Wordpress
|
|
|
|
page_description: Getting started with Docker Compose and Rails
|
|
|
|
page_keywords: documentation, docs, docker, compose, orchestration, containers,
|
|
|
|
wordpress
|
2014-01-27 22:43:22 +01:00
|
|
|
|
2015-02-27 03:58:06 +01:00
|
|
|
## Getting started with Compose and Wordpress
|
2014-01-27 22:43:22 +01:00
|
|
|
|
2015-02-27 03:58:06 +01:00
|
|
|
You can use Compose to easily run Wordpress in an isolated environment built
|
|
|
|
with Docker containers.
|
|
|
|
|
|
|
|
### Define the project
|
|
|
|
|
|
|
|
First, [Install Compose](install.md) and then download Wordpress into the
|
|
|
|
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
|
|
|
|
2014-02-18 11:52:24 +01: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
|
|
|
|
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
|
|
|
|
|
|
|
```
|
|
|
|
web:
|
|
|
|
build: .
|
2014-02-18 11:52:24 +01:00
|
|
|
command: php -S 0.0.0.0:8000 -t /code
|
2014-01-27 22:43:22 +01:00
|
|
|
ports:
|
2014-02-20 13:53:43 +01:00
|
|
|
- "8000:8000"
|
2014-01-27 22:43:22 +01:00
|
|
|
links:
|
|
|
|
- db
|
2014-02-18 11:52:24 +01:00
|
|
|
volumes:
|
|
|
|
- .:/code
|
2014-01-27 22:43:22 +01:00
|
|
|
db:
|
|
|
|
image: orchardup/mysql
|
|
|
|
environment:
|
|
|
|
MYSQL_DATABASE: wordpress
|
|
|
|
```
|
|
|
|
|
2015-02-27 03:58:06 +01:00
|
|
|
Two supporting files are needed to get this working - first, `wp-config.php` is
|
|
|
|
the standard Wordpress config file with a single change to point the database
|
|
|
|
configuration at the `db` container:
|
2014-01-27 22:43:22 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
<?php
|
|
|
|
define('DB_NAME', 'wordpress');
|
|
|
|
define('DB_USER', 'root');
|
|
|
|
define('DB_PASSWORD', '');
|
2014-08-08 20:00:10 +02:00
|
|
|
define('DB_HOST', "db:3306");
|
2014-01-27 22:43:22 +01:00
|
|
|
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');
|
|
|
|
```
|
|
|
|
|
2015-02-27 03:58:06 +01:00
|
|
|
Second, `router.php` tells PHP's built-in web server how to run Wordpress:
|
2014-01-27 22:43:22 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$root = $_SERVER['DOCUMENT_ROOT'];
|
|
|
|
chdir($root);
|
|
|
|
$path = '/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'/');
|
|
|
|
set_include_path(get_include_path().':'.__DIR__);
|
|
|
|
if(file_exists($root.$path))
|
|
|
|
{
|
|
|
|
if(is_dir($root.$path) && substr($path,strlen($path) - 1, 1) !== '/')
|
|
|
|
$path = rtrim($path,'/').'/index.php';
|
|
|
|
if(strpos($path,'.php') === false) return false;
|
|
|
|
else {
|
|
|
|
chdir(dirname($root.$path));
|
|
|
|
require_once $root.$path;
|
|
|
|
}
|
|
|
|
}else include_once 'index.php';
|
|
|
|
```
|
2015-02-27 03:58:06 +01:00
|
|
|
### Build the project
|
2014-01-27 22:43:22 +01:00
|
|
|
|
2015-02-27 03:58:06 +01:00
|
|
|
With those four files in place, run `docker-compose up` inside your Wordpress
|
|
|
|
directory and it'll pull and build the needed images, and then start the web and
|
|
|
|
database containers. You'll then be able to visit Wordpress at port 8000 on your
|
|
|
|
Docker daemon (if you're using Boot2docker, `boot2docker ip` will tell you its
|
|
|
|
address).
|
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
|
|
|
|
|
|
|
- [Installing Compose](install.md)
|
|
|
|
- [User guide](index.md)
|
|
|
|
- [Command line reference](cli.md)
|
|
|
|
- [Yaml file reference](yml.md)
|
|
|
|
- [Compose environment variables](env.md)
|
|
|
|
- [Compose command line completion](completion.md)
|