Skip to content

Instantly share code, notes, and snippets.

@ginpei
Created November 8, 2017 06:48
Show Gist options
  • Save ginpei/b1672e0ea6b7fad82e87c72966077353 to your computer and use it in GitHub Desktop.
Save ginpei/b1672e0ea6b7fad82e87c72966077353 to your computer and use it in GitHub Desktop.

Docker library/wordpress

Usage

Basic

To start:

$ docker run --rm -d --name my-mysql -e MYSQL_ROOT_PASSWORD=passwd mysql
$ docker run --rm -d --name my-wordpress --link my-mysql:mysql -p 80:80 wordpress

Then open http://localhost. It might take a minute to connect to the server successfully.

To stop:

$ docker stop my-mysql my-wordpress

You can change following values.

  • my-mysql ... Name of the MySQL container.
  • my-wordpress ... Name of the WordPress container.
  • passwd ... Password for the MySQL DB.
  • 80 ... Port to access the WP site. It can be like 8080:80 to access via http://localhost:8080.

Keep your data

Add -v or --volume options.

$ docker run --rm -d --name my-mysql -e MYSQL_ROOT_PASSWORD=passwd -v `pwd`/db:/var/lib/mysql mysql
$ docker run --rm -d --name my-wordpress --link my-mysql:mysql -p 80:80 -v `pwd`/wp:/var/www/html wordpress

Then keep directories db and wp.

If you prefer Windows, replace pwd and surrounding back quotes with %CD%.

Note: Remember you have to specify local directories in FULL PATH. ./db doesn't work.

Environment variables

You have to set the following variable to MySQL using -e or --env.

  • MYSQL_ROOT_PASSWORD

For WordPress, there are some environments you can set if you want. Find them at the documentation.

Variations

There are lots of variations sets for a container.

For example:

  • 4.8.3-php7.1-fpm-alpine
  • 4.8.2-php5.6-apache
  • cli-1.4.0-php7.1

Check the documentation for full information.

CLI

A tag cli and its variations provide you CLI tool.

Use --volumes-from and --link options to access your WordPress environment and drive them through the tool.

$ docker run --rm -ti --volumes-from my-wordpress --link my-mysql:mysql wordpress:cli plugin list
+---------+----------+-----------+---------+
| name    | status   | update    | version |
+---------+----------+-----------+---------+
| akismet | inactive | available | 4.0     |
| hello   | inactive | none      | 1.6     |
+---------+----------+-----------+---------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment