singlewp
directory created while watching this week's
videos and name the new directory doublewp
.
.env
file from which we will provide passwords to our
systems.
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: exampledbwould 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.
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:
.env
file on the host server (not in the MySQL container).
.env
file we need to run the script on the
host server.
docker exec
to connect to the container
passing the values as environment variables. The script will require
a parameter (1, 2, 3, etc.) to identify which set of environment
variables should be passed.
Once connected to the container it will execute the MySQL container script.
Here are links to my versions of these scripts:
https://josephus.hsutx.edu/classes/sa/source/installdb
https://josephus.hsutx.edu/classes/sa/source/add-new-wp-db
You'll need to change them to match your variable names and configuration. I used a Dockerfile to install the MySQL container script into the container. If you do that you'll create a subdirectory for the Dockerfile and the script and then use the build directive (rather than image) in your YAML file.
To test this functionality you'll need to delete the existing volume that contains the mysql data and remove the commands in the YAML file that cause a new MySQL user to be created. Then make changes a needed and test.
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.
tsergeant@hsutx.edu
with instructions on where to find your work on your server.