mirror of https://github.com/docker/compose.git
Updated Wordpress tutorial
The new tutorial now uses official Wordpress Docker Image. Signed-off-by: Sanyam Kapoor <1sanyamkapoor@gmail.com>
This commit is contained in:
parent
958f96c78a
commit
d4e9a3b6b1
|
@ -22,7 +22,7 @@ with Docker containers. This quick-start guide demonstrates how to use Compose t
|
||||||
|
|
||||||
You can name the directory something easy for you to remember. This directory is the context for your application image. The directory should only contain resources to build that image.
|
You can name the directory something easy for you to remember. This directory is the context for your application image. The directory should only contain resources to build that image.
|
||||||
|
|
||||||
This project directory will contain a `Dockerfile`, a `docker-compose.yaml` file, along with a downloaded `wordpress` directory and a custom `wp-config.php`, all of which you will create in the following steps.
|
This project directory will contain a `docker-compose.yaml` file which will be complete in itself for a good starter wordpress project.
|
||||||
|
|
||||||
2. Change directories into your project directory.
|
2. Change directories into your project directory.
|
||||||
|
|
||||||
|
@ -30,113 +30,50 @@ with Docker containers. This quick-start guide demonstrates how to use Compose t
|
||||||
|
|
||||||
$ cd my-wordpress/
|
$ cd my-wordpress/
|
||||||
|
|
||||||
3. Create a `Dockerfile`, a file that defines the environment in which your application will run.
|
3. Create a `docker-compose.yml` file that will start your `Wordpress` blog and a separate `MySQL` instance with a volume mount for data persistence:
|
||||||
|
|
||||||
For more information on how to write Dockerfiles, see the [Docker Engine 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 include these two lines:
|
|
||||||
|
|
||||||
FROM php:5.6-fpm
|
|
||||||
RUN docker-php-ext-install mysql
|
|
||||||
ADD . /code
|
|
||||||
CMD php -S 0.0.0.0:8000 -t /code/wordpress/
|
|
||||||
|
|
||||||
This tells the Docker Engine daemon how to build an image defining a container that contains PHP and WordPress.
|
|
||||||
|
|
||||||
4. Create a `docker-compose.yml` file that will start your web service and a separate MySQL instance:
|
|
||||||
|
|
||||||
version: '2'
|
version: '2'
|
||||||
services:
|
services:
|
||||||
web:
|
|
||||||
build: .
|
|
||||||
ports:
|
|
||||||
- "8000:8000"
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
volumes:
|
|
||||||
- .:/code
|
|
||||||
db:
|
db:
|
||||||
image: mysql
|
image: mysql:5.7
|
||||||
|
volumes:
|
||||||
|
- "./.data/db:/var/lib/mysql"
|
||||||
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
MYSQL_ROOT_PASSWORD: wordpress
|
MYSQL_ROOT_PASSWORD: wordpress
|
||||||
MYSQL_DATABASE: wordpress
|
MYSQL_DATABASE: wordpress
|
||||||
MYSQL_USER: wordpress
|
MYSQL_USER: wordpress
|
||||||
MYSQL_PASSWORD: wordpress
|
MYSQL_PASSWORD: wordpress
|
||||||
|
|
||||||
5. Download WordPress into the current directory:
|
wordpress:
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
image: wordpress:latest
|
||||||
|
links:
|
||||||
|
- db
|
||||||
|
ports:
|
||||||
|
- "8000:80"
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
WORDPRESS_DB_HOST: db:3306
|
||||||
|
WORDPRESS_DB_PASSWORD: wordpress
|
||||||
|
|
||||||
$ curl https://wordpress.org/latest.tar.gz | tar -xvzf -
|
**NOTE**: The folder `./.data/db` will be automatically created in the project directory
|
||||||
|
alongside the `docker-compose.yml` which will persist any updates made by wordpress to the
|
||||||
This creates a directory called `wordpress` in your project directory.
|
database.
|
||||||
|
|
||||||
6. Create a `wp-config.php` file within the `wordpress` directory.
|
|
||||||
|
|
||||||
A supporting file is needed to get this working. At the top level of the wordpress directory, add a new file called `wp-config.php` as shown. This is the standard WordPress config file with a single change to point the database configuration at the `db` container:
|
|
||||||
|
|
||||||
<?php
|
|
||||||
define('DB_NAME', 'wordpress');
|
|
||||||
define('DB_USER', 'wordpress');
|
|
||||||
define('DB_PASSWORD', 'wordpress');
|
|
||||||
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');
|
|
||||||
?>
|
|
||||||
|
|
||||||
7. Verify the contents and structure of your project directory.
|
|
||||||
<!--
|
|
||||||
Dockerfile
|
|
||||||
docker-compose.yaml
|
|
||||||
wordpress/
|
|
||||||
index.php
|
|
||||||
license.txt
|
|
||||||
readme.html
|
|
||||||
wp-activate.php
|
|
||||||
wp-admin/
|
|
||||||
wp-blog-header.php
|
|
||||||
wp-comments-post.php
|
|
||||||
wp-config-sample.php
|
|
||||||
wp-config.php
|
|
||||||
wp-content/
|
|
||||||
wp-cron.php
|
|
||||||
wp-includes/
|
|
||||||
wp-links-opml.php
|
|
||||||
wp-load.php
|
|
||||||
wp-login.php
|
|
||||||
wp-mail.php
|
|
||||||
wp-settings.php
|
|
||||||
wp-signup.php
|
|
||||||
wp-trackback.php
|
|
||||||
xmlrpc.php
|
|
||||||
-->
|
|
||||||
|
|
||||||
![WordPress files](images/wordpress-files.png)
|
|
||||||
|
|
||||||
### Build the project
|
### Build the project
|
||||||
|
|
||||||
With those four new files in place, run `docker-compose up` from your project directory. This will pull and build the needed images, and then start the web and database containers.
|
Now, run `docker-compose up -d` from your project directory. This will pull the needed images, and then start the wordpress and 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.
|
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.
|
||||||
|
|
||||||
At this point, WordPress should be running on port `8000` of your Docker Host, and you can complete the "famous five-minute installation" as a WordPress administrator.
|
At this point, WordPress should be running on port `8000` of your Docker Host, and you can complete the "famous five-minute installation" as a WordPress administrator.
|
||||||
|
|
||||||
|
**NOTE**: The Wordpress site will not be immediately available on port `8000` because
|
||||||
|
the containers are still being initialized and may take a couple of minutes before the
|
||||||
|
first load.
|
||||||
|
|
||||||
![Choose language for WordPress install](images/wordpress-lang.png)
|
![Choose language for WordPress install](images/wordpress-lang.png)
|
||||||
|
|
||||||
![WordPress Welcome](images/wordpress-welcome.png)
|
![WordPress Welcome](images/wordpress-welcome.png)
|
||||||
|
|
Loading…
Reference in New Issue