Running a local docker instance for Wordpress theme development
I wanted to update the Leaf theme (the one I’m currently using) and I haven’t had wordpress on my computer in a long time.
Instead of going through the whole set up again, I decided to use docker for this.
I wanted to keep the setup to a minimal and also make it portable for future use, below are the steps you’ll need to get it running.
- Install Docker (I’m on mac, so I just have the docker app).
- Make a directory that you can call something like wordpress-docker, this is where the docker-compose.yml file will live.
- Add the following to the docker-compose.yml file:
version: ‘3.1’
services:
wordpress: image: wordpress restart: always ports:
- 8080:80 environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: password WORDPRESS_DB_NAME: wordpress volumes:
- wordpress:/var/www/html
- ../leaf:/var/www/html/wp-content/themes/leaf # --- this assumes we have leaf one dir up
db: image: mysql:5.7 restart: always environment: MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: password MYSQL_RANDOM_ROOT_PASSWORD: ‘1’ volumes:
- db:/var/lib/mysql
volumes: wordpress: db:
-
Start up the docker instances by running docker-compose up (from within wordpress-docker)
-
Go to localhost:8080, you should see the wordpress instance.
-
After the setup is complete, go to localhost:8080/wp-admin/themes.php and you should see the theme for development too.