I often finding myself having to quickly test an update, change, theme or plugin for friends, family or clients who run on WordPress. Setting up a new WordPress config can be quite time consuming, and often that setup time outweighs the actual quick test or work you need to do – This annoys me greatly.
Below are a few little docker commands to quickly spin up that dev environment for quick playing and testing.
The ‘uploads.ini’ file needs to be present next to the two shells scripts – this is because by default the maintainers ‘wordpress’ image has a very low upload limit which will prevent you from uploading themes and plugins to the WordPress instance.
file_uploads = On memory_limit = 64M upload_max_filesize = 64M post_max_size = 64M max_execution_time = 600
docker run --rm -d \ -p3306:3306 --name wp-mysql \ -eMYSQL_ROOT_PASSWORD=secret \ -eMYSQL_DATABASE=wordpress \ mysql:5.7 docker run --rm -d \ -p8080:80 --name wordpress \ --link wp-mysql:mysql \ -v /$(pwd)/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini \ wordpress docker run --rm -d \ -p8081:80 --name wp-phpma \ --link wp-mysql:mysql \ -ePMA_HOST=mysql \ -ePMA_USER=root \ -ePMA_PASSWORD=secret \ phpmyadmin/phpmyadmin
docker stop wordpress wp-mysql wp-phpma
What do these scripts do?
Well, reading them through, ‘start.sh’ first boots up a MySQL 5.7 container with the credentials root & secret, database name ‘wordpress’, exposing port 3306, naming it ‘wp-mysql’, putting it into the background and upon stopping removing all existence of itself.
Second, it will start a ‘wordpress’ container direct from the maintainers image – this will be the latest version of WordPress. It exposes the container on port 8080 and links it to the MySQL database. It volume maps the ‘uploads.ini’ file into the required place in the container.
Finally, and as an addition a PHPMyAdmin container is spun up, exposed on port 8081, linked to the database container and forcefully toldwhere to find that database, and the credentials for it via the environment variables.
‘stop.sh’ on the other hand – just stops these containers, and as they are all started with the ‘–rm’ flag – they will be removed.
A word of caution
These little scripts are literally for spinning up a WordPress instance quickly, doing something and shutting down again – all work is lost…