HW11: Docker Web App due Sat 11 Nov 23:59

\begin{purpose}
This assignment provides practice using the \verb\vert docker-c...
...rocess of using docker to implement more than one WordPress site.
\end{purpose}

The Big Picture

By the end of the next homework assignment we will have built a docker system that allows simple creation of new wordpress sites by making some simple edits to configuration files and then running docker-compose. In this assignment we will make progress toward that end as follows:
  1. Copy the singlewp directory created while watching this week's videos and name the new directory doublewp.
  2. Create a .env file from which we will provide passwords to our systems.
  3. Modify the MySQL container so that we set the root password and write a script that will create a database and user for the WordPress app as needed.
  4. Add a second WordPress container (mapping it to port 8081). We'll keep a single MySQL container and simply add a new database/user to support the application.

Using an ENV File

If you haven't done so already go ahead a create the doublewp directory as described above and make sure it has a copy of the stock docker-compose.yml file.

In that directory create a new file named .env. In this file we are going put environment variables that we want to use in our docker-compose.yml file. In the .env file you will create environment variables to hold the following values: root MySQL password, name of wordpress database, name of wordpress database user, the password for the database user. It is conventional to use all CAPS for environment variables. NOTE: We will (later) be adding a second WordPress container. That second container will make use of the same MySQL container as the first, but will need access to a different database, database user, and password. So, you may want to consider naming your variables something like: WP_DB_1, WP_USER_1, WP_PASSWORD_1, WP_DB_2, etc.

Once the variables have been set you can modify your docker-compose.yml file to use them. So, the line that reads:

MYSQL_DATABASE: exampledb
would be replaced with:
MYSQL_DATABASE: ${WP_DB_1}
Execute: docker-compose up -d(if you use the naming scheme I mentioned above).

Also, you'll no longer want MYSQL to use a random root password. Instead it should use the value you specified in the env file.

Test your new YAML file.

Modifying the MySQL Container Setup

Imagine in the future we might have 20 different WordPress sites all sharing a single MySQL container. That means your MySQL container will have 20 database, 20 non-root users, with 20 passwords. The standard MySQL container doesn't have a way for you to set those values in the docker-compose.yml file. Instead we'll need to create these additional databases, users, and passwords by running a script.

Things to remember about how this script will have to run:

Add a Second WordPress Container

Once you have the above parts working you can add a second WordPress container by:
  1. Edit the env file to have a database/user/password with a suffix of 2.
  2. Edit the YAML file to have another wordpress definition. It will basically be a copy of the original one. You'll need to change the name, and map it to a different port than the first (perhaps 8081). It will also need a separate volume.
  3. Execute the installdb script (with a parameter of 2) to create the database/user/password in the MySQL container.
  4. Execute: docker-compose up -d

Test this configuration and verify that you can connect to both sites. You may want to use the lynx text-based browser from your server to remove the need for a second layer of port-forwarding.

Turning In Your Work

When you are finished with this assignment send email to tsergeant@hsutx.edu with instructions on where to find your work on your server.