I have been using Docker for a while already. I keep putting it to the side and playing with other stuff. But, a client contacted me wanting to configure WordPress locally for testing a new theme release. I said to myself, I need to write this down and also brew a cup of Catimor coffee at home before I start working on this one.
The more fine way to configure WordPress locally using Docker is to use Docker compose. I like it because it allows me to configure most settings using on .yml file. Create your .yml file using your favorite text editor (I use vim) and name it docker-compose.yml.
services:
db:
image: mariadb:10.6.4-focal
command: '--default-authentication-plugin=mysql_native_password'
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=wordpress
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=wordpress
expose:
- 3306
- 33060
wordpress:
image: wordpress:latest
volumes:
- wp_data:/var/www/html
ports:
- 80:80
restart: always
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
volumes:
db_data:
wp_data:Next, open your Terminal and run:
docker compose -up -d-d option will run in detach mode.
volumes:
db_data:
wp_data:
The volumes section will persist database updates made by WordPress and updates to themes and plugins. Very cool feature!
You will see a bunch of text passing by your Terminal
Creating network "my_wordpress_default" with the default driver
Pulling db (mariadb:10.6.4-focal)...
5.7: Pulling from library/mariadb
efd26ecc9548: Pull complete
a3ed95caeb02: Pull complete
<...>
Digest: sha256:34a0aca88e85f2efa5edff1cea77cf5d3147ad93545dbec99cfe705b03c520de
Status: Downloaded newer image for mariadb:10.6
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordOpen your browser to bring up WordPress installer

Go by the entire setup process same as you normally do. Play around when done you can run on your Terminal:
docker compose downIt will remove the container and default network. It will preserve WordPress database.
Another command to remove the above plus the database is:
docker compose down --volumesThere are more settings you can pass to the WordPress install in your docker-compose.yml file. I will look for them later. I hope you like this brief tutorial. Contact me if you have any questions. Also, check out some of my cool coffee mugs and T-Shirt designs in my IT Handyman shop.

