As someone who has been using Docker for local development over the past five years, I can confidently say that it has been a game changer for me. Gone are the days of struggling with conflicting dependencies, setting up multiple virtual environments, and manually configuring development environments on different machines. With Docker, I have been able to streamline my development process, increase my productivity, and easily replicate my environments across different projects and machines.
In this article, I’ll share a configuration that worked for me all these years. Of course, it got many modifications over the years, but here’s the latest minimal version of it.
docker-compose.yml
— drop this file in the root of your project
version: '3'
services:
wordpress:
image: wordpress:latest
depends_on:
- mysql
links:
- mysql
ports:
- 8000:80
restart: always
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wp-app
WORDPRESS_DEBUG: 1
WORDPRESS_TABLE_PREFIX: wp_
WORDPRESS_CONFIG_EXTRA: |
define('FS_METHOD', 'direct');
define('SCRIPT_DEBUG', true);
volumes:
- ./.srv/wordpress/:/var/www/html
- ./.srv/log/:/var/log
- ./custom.ini:/usr/local/etc/php/conf.d/custom.ini
wpcli:
depends_on:
- mysql
- wordpress
image: wordpress:cli
links:
- mysql:mysql
entrypoint: wp
command: "--info"
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wp-app
WORDPRESS_DEBUG: 1
WORDPRESS_TABLE_PREFIX: wp_
WORDPRESS_CONFIG_EXTRA: |
define('FS_METHOD', 'direct');
volumes:
- ./.srv/wordpress/:/var/www/html
- ./.srv/log/:/var/log
- ./custom.ini:/usr/local/etc/php/conf.d/custom.ini
mysql:
image: mysql:5.7
restart: always
ports:
- 3306:3306
volumes:
- "./.srv/database:/var/lib/mysql"
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wp-app
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
custom.ini
— drop this file in the root of your project
file_uploads = On
memory_limit = 3072M
upload_max_filesize = 3072M
post_max_size = 3072M
max_execution_time = 1200
max_input_vars = 2000
What does this:
This allows the installation of WordPress, PHP, MySQL, and WP-CLI. All you need to work on a WordPress project.
Run docker-compose up -d
. This command will install everything for you. When done, go to http://localhost:8000, follow the installation process, and enjoy your new local server.
Docker configuration comes with WP CLI. To use it run:
docker-compose run --rm wpcli <your_command>
because the above command is too long, create an alias:
alias wp="docker-compose run --rm wpcli"
Now you can use the simple wp
command to run WP CLI commands.
That’s it 🙂