If you’ve never used Docker or configured a basic Docker setup for WordPress before this blog post will guide you through the very simple process on how to do just that!
In December 2017 I decided to update my personal website (this one!), but instead of picking a new WordPress theme I wanted to create and maintain my own personal theme as both a learning experience and for more control over the theme.
Having limited experience with complex PHP projects I also decided I wanted to look into better ways of managing a working environment for my PHP projects; especially those involving databases.
I considered a variety of different virtual machine solutions that would create an isolated testing environment; but I couldn’t find a solution that met my requirements, which were:
- Little to no dependencies
- Small install size
- Small system resource footprint
- Easily portable
As I had been recommended to check out Docker a lot lately; and from what I had heard it seemed to meet all of my requirements I decided to give it a go. The install and setup process was remarkably simple!
The steps I followed were as follows:
Setting Up Docker
- Install Docker
- Restart your PC to enable Virtualization
- Right Click the Docker icon in your System Tray and select ‘Settings’
- Click ‘Shared Drives’ and enable the drive you want to store your WordPress site for development
- Click ‘Apply’, your PC might need to restart to allow Docker access to these drives.
Setting Up Your WordPress Environment
- Create a new folder somewhere on one of the drives you shared with Docker
- Create a new file named ‘docker-compose.yml’ in the folder you just created
- Paste the following into the file:
version: "2" services: wp-db: image: mariadb expose: - "3306" environment: MYSQL_ROOT_PASSWORD: DefaultPassword wp: image: wordpress volumes: - ./:/var/www/html ports: - "8080:80" links: - wp-db:mysql environment: WORDPRESS_DB_PASSWORD: DefaultPassword
- Open a command window pointing to the folder you just created.
- Type ‘docker-compose up -d’ into the command window.
- Navigate to http://localhost:8080/ and configure WordPress
You can stop your docker containers by entering ‘docker-compose stop’ into the command window.
Keep in mind this isn’t the best way to manage your WordPress projects in Docker and is no where near production ready, but for a quick test or a small project this setup is perfectly fine.
This blog post, and my easy setup of a WordPress Docker environment was heavily inspired by A. Tate Barber, so make sure to check out his original article here. He also wrote a follow up article that looks at setting up more advanced functionality which is viewable here.