How to deploy a WordPress with Marathon
In this tutorial, we’ll see how to deploy a WordPress CMS, along with a MySQL database and a PhpMyAdmin management web interface.
As the Docker PaaS does not yet support stateful containers, we’ll order the database from the PaaS DB MySQL.
First and foremost
If you haven’t already read our introduction to Docker with Mesos and Marathon, you should probably read it before diving in.
Installing the MySQL database
For your MySQL instance to be fully operational, you need to complete the following steps:
- create a database (eg: WordPress)
- create a user account protected by a password, with read-write rights on the previously created database
You can refer to the PaaS DB tutorial for more details.
Restrict access to the database to your container IPs
In order to make your database accessible from your containers only, you have to specify which IPs are authorized to connect to your instance. You can get your containers IP in the manager (a container IP is the public IP of the slave it is running on).
Deploy the PhpMyAdmin manager
We’ll use the https://hub.docker.com/r/phpmyadmin/phpmyadmin/ image, hosted on the Docker Hub.
You’ll need to configure the PhpMyAdmin so that it exposes the TCP container port 80 to the load balancer.
You then need to set environment variables, to define the host and port of your MySQL database:
PMA_HOSTS: the value listed in the sunrise manager, section “Paas Database”, in the project instance details page, under the name “Access URL”
PMA_PORT: the value listed in the sunrise manager, section “Paas Database”, in the project instance details page, under the name “Service port”
Finally, configure an HTTP health-check on the path
Once your app is displayed as healthy in your marathon web interface, you should be able to access the PhpMyAdmin welcome page by requesting the configured vhost. In the previous screenshot, we set it to
Deploy the WordPress container
We’ll use the official wordpress image, hosted on the Docker Hub.
Similarly to PhpMyAdmin, we need to:
- expose the TCP container port 80 on the LB
- configure the container environment to define the DB host, port, and credentials
- add the Paas Logs label to be able to see the container logs in the PaaS Logs Graylog
- configure the container vhost
- configure the container HTTP health checks
Once again, you should be able to reach the WordPress welcome page by requesting the configured vhost.
You now have 3 stateless WordPress containers, communicating with a MySQL database, which you can manage from a web interface.
To customize your WordPress (ie: add themes, plugins, etc), you’ll need to add them to the image at build time.
When we support stateful containers, you’ll be able to tweak your instance and have any changes persisted, even after a container redeploy.