Dylan in Canada
As I have started contributing to ItsMOSS, one challenge for me has been using WordPress again. I used WordPress briefly about 8 years ago to help maintain a site for an organization I was involved with, but I haven’t touched it since.
So rather than jump back in unprepared, I decided that I should set up WordPress locally and play around to try and remind myself of how things work.
I did some reading and realized that an option is to run this through Docker. I had been wanting to get into Docker for some time now and this seemed like a good opportunity to learn.
So I set out to learn how to run a local WordPress using Docker. It seemed simple enough, and really the process is not complicated. However, I found the available guides did not work for me.
What follows is an amalgamation of several approaches that finally allowed me to get it working. I have tested this successfully on Ubuntu 20.04 and Linux Mint 20.1, and presumably it will work on most distributions (with adjustment for the appropriate install commands).
By no means is this meant to be the definitive guide to doing this, just something that will hopefully help others who want to try this.
Step 1: Install Docker from Terminal
sudo apt install docker.io
Step 2: Install Docker Compose from Terminal
sudo apt install docker-compose
3. Create a folder for the WordPress container and create a Docker compose file for the container
mkdir wordpress-local && cd wordpress-local
touch docker-compose.yml
4. Open your docker compose file (docker-compose.yml) in a text editor
If you used the above commands then the file will be found in home/wordpress-local/docker-compose.yml
5. Add the following text to your docker-compose.yml file
web:
image: wordpress
links:
- mysql
environment:
- WORDPRESS_DB_PASSWORD=password
ports:
- "127.0.0.3:8080:80"
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=my-wpdb
6. Save your docker-compose.yml file
7. While in your WordPress directory, run docker compose to pull the material for the wordpress container.
sudo docker-compose up -d
Important:
You must be in home/wordpress-local/ for this command to work.
8. Run the local WordPress installer by visiting
127.0.0.3:8080
in your preferred browser.
9. Follow the on-screen prompts to install your WordPress site
10. You can access the admin
login for your WordPress site
at any point by visiting
http://127.0.0.3:8080/wp-admin/
11. If you turn off or restart your computer, you can re-activate your local wordpress container by simply repeating steps 7-10.