Docker Compose for local WordPress development
Docker, specifically Docker compose, has served me well in keeping a sane development environment for my WordPress projects. MAMP was too much of a black box, and having a local PHP and SQL for both MediaWiki and WordPress was going to be more maintenance than I would have time for. With compose I have little to no maintenance burden, and my system is squeaky clean.
docker-compose.yml file starts two services — using the
mysql, and the
version: '3.3' services: db: image: mysql:5.7 volumes: - ./dbdata:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest ports: - "8008:80" volumes: - ./wp-content:/var/www/html/wp-content restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress
The way this is setup is that both the services share a part of their file system with the host. The
mysql one shares all the database data, making it easier for me to move test data around different instances and configurations of WordPress that I might be running. And, to be able to work on plugins and themes the
wordpress service shares the
wp-content directory. This way, I can easily clone and work on anything directly on my local system.
With this, all I need to do now to setup a new WordPress install is — create a new directory, copy this YAML file into it, and run
docker-compose up. I change the
wordpress service’s port mapping when I need to run multiple instances at once. That’s it!