I want to run my existing Wordpress site on Docker for local development.
This is my docker-compose file:
version: '2'
services:
mysql:
image: mysql:5.7
volumes:
- "./.data/db:/var/lib/mysql"
ports:
- "9306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: example_password
MYSQL_DATABASE: example_database_name
wordpress:
image: wordpress
volumes:
- "./:/var/www/html"
links:
- mysql
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_PASSWORD: example_password
WORDPRESS_DB_NAME: example_database_name
However, the problem I have with the offical Wordpress Docker image is that it insists on installing Wordpress. This is fine if you don't have Wordpress installed, but causes a LOT of problems if already have it installed. This is especially frustrating because I organised my folders so all the internal wordpress files are in a separate folder called "wp", with "wp-content" on a separate directory.
So my question is how can I run my existing Wordpress site using Docker.
Your best bet if you want to use the official image is going to be to mount the wp-content
directory not the entire www
directory, like:
-v /path/to/my/blog/wp-content:/var/www/html/wp-content
and adjust the custom set-up you have involving your "wp" directory. Wordpress expects a certain directory structure, so depending on why you broke out your files you may or may not be able to use the default container. The nice thing about using it this way is you can update WP simply by updating the container and all your files remain protected.
If you needs are too custom for that, as mentioned, you can try using the WP Dockerfile and edit to suit you needs, but if you can use the standard wp-content
structure, it's going to make things simpler to manage and maintain.