Deploying WordPress with MySQL in Linked Docker Containers
School
Thomas Jefferson School of Law**We aren't endorsed by this school
Course
AMJUR 635A
Subject
Information Systems
Date
Dec 12, 2024
Pages
2
Uploaded by kj6n0kx24
concerns using containers and helps create a microservices-based design for your application (see Building Microservices (http://bit.ly/building-microservices)). Ulti- mately, this will help with scale and resiliency. See Also « Supervisor documentation (http://supervisord.org/index.html) « Docker Supervisor article (https://docs.docker.com/articles/using_supervisord/) 1.16 Running a WordPress Blog Using Two Linked Containers Problem You want to run a WordPress (http://wordpress.com) site with containers, but you do not want to run the MySQL database in the same container as WordPress. You want to keep the concept of separation of concerns in mind and decouple the various com- ponents of an application as much as possible. Solution You start two containers: one running WordPress using the official image from the Docker Hub (http://hub.docker.com), and one running the MySQL database. The two containers are linked using the - -1ink option of the Docker CLIL Start by pulling the latest images for WordPress (https://hub.docker.com/_/wordpress/) and MySQL (https://.hub.docker.com/_/mysql/): $ docker pull wordpress:latest $ docker pull mysgl:latest $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE mysql latest 9def920de0a2 4 days ago 282.9 MB wordpress latest 93acfaf85c71 8 days ago 472.8 MB Start a MySQL container, give it a name via the --name CLI option, and set the MYSQL_ROOT_PASSWORD via an environment variable: $ docker run --name mysqlwp -e MYSQL_ROOT_PASSWORD=wordpressdocker -d mysql By not specifying the tag for the mysql image, Docker automatically chose the latest tag, which is the one you downloaded specifically. The container was daemonized with the -d option. 28 | Chapter 1: Getting Started with Docker
You can now run a WordPress container based on the wordpress:latest image. It will be linked to the MySQL container using the --1ink option, which means that Docker will automatically set up the networking so that the ports exposed by the MySQL con- tainer are reachable inside the WordPress container: $ docker run --name wordpress --link mysqlwp:mysql -p 80:80 -d wordpress Both containers should be running in the background, with port 80 of the WordPress container mapped to port 80 of the host: $ docker ps CONTAINER ID IMAGE e1593e7a20df wordpress:latest d4be18e33153 mysql:latest STATUS Up About a minute Up 5 minutes COMMAND " /entrypoint.sh apac "/entrypoint.sh mysq PORTS 3306/tcp 0.0.0.0:80->80/tcp CREATED About a minute ago 5 minutes ago NAMES wordpress mysqlwp Open a browser at http://<ip_of_host> and it should show the WordPress installation screen with the language selection window, as shown in Figure 1-10. If you go through the WordPress setup, you will then have a fully functional WordPress site running with two linked containers. Dashboard Welcome to WordPress! Recently Published Comments We've assembled some links to get you started: Get Started Next Steps K write your firs 4+ Add an About or, change your theme stely @ View your site At a Glance 1 post ] ¥ 1 Comment WordPress 4.1 running Twenty Fifteen theme. Search Engines Discouraged Activity Howdy, docker [l 3 Dismiss More Actions t blog post B Manage widgets or menus page @ Turn comments on or off = Learn more about getting started Quick Draft Title What's on your mind? WordPress News WordPress 4,1 "Dinah” December 18, 2014 Figure 1-10. Working WordPress site within containers 1.16 Running a WordPress Blog Using Two Linked Containers 29