I am running the latest Docker mac app and have created a new docker-compose.yml
in my project directory. (which is my wordpress theme).
This is my configuration docker-compose.yml
file below...
version: '3.7'
networks:
wordpress:
ipam:
config:
- subnet: 172.25.0.0/16
services:
db:
image: mysql:5.7
volumes:
- ./db:/var/lib/mysql:delegated
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- .:/var/www/html/wp-content/themes/testing:delegated
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_AUTH_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_SECURE_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_LOGGED_IN_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_NONCE_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_SECURE_AUTH_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_LOGGED_IN_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_NONCE_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_DEBUG: 1
networks:
- wordpress
So far i'm finding it awesome. I had a few issues with getting the database to be persistent, and figuring out that wp-content
folder needs the owner to be set to www-data
.
But after fixing the above, it's working so good and if I docker-compose down
and up
my database is persistent. Plus my database is being pulled from my local theme.
What lets it down is that my plugins folder resets itself if I docker-compose down
or docker-compose rm
.
Is there some way I could map a local folder from my mac or project theme folder? Then I can store my plugins here so when I docker-compose up -d
it remembers my plugins.
Any ideas would be awesome.
For example I could put the plugins folder in my local theme folder project...
SOLVED!
Because I'm running local dev, npm, composer etc. My aim is to keep a real simple folder structure so my theme is the route of my project in phpStorm.
I've now included my plugins and uploads folder for local persistent data in my theme route project folder by adding following volume mapping (see code below).
This is not your classic Wordpress structure, but I'm not committing plugins
and uploads
to version control or my staging server environment. These are purely here for my local persistent data incase I docker-compose down
.
See my phpStorm project structure now...
See my docker-compose.yml
config file...
version: '3.7'
networks:
wordpress:
ipam:
config:
- subnet: 172.25.0.0/16
services:
db:
image: mysql:5.7
volumes:
- ./db:/var/lib/mysql:delegated
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- .:/var/www/html/wp-content/themes/testing:delegated
- ./plugins:/var/www/html/wp-content/plugins
- ./uploads:/var/www/html/wp-content/uploads
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_AUTH_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_SECURE_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_LOGGED_IN_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_NONCE_KEY: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_SECURE_AUTH_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_LOGGED_IN_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_NONCE_SALT: 5f6ede1b94d25a2294e29eeba929a8c80a5ac0fb
WORDPRESS_DEBUG: 1
networks:
- wordpress
Thanks @Ludi Sistemaš for your help.
Yes, there is a way. You firstly need to rearrange directorys structure. On your host machine, your using themes directory for mount point. Lets say your going to do it like this. Make new directory on your host machine, and call it wp-content. Now you can edit just this line in your docker-compose file which needs to be moved inside of this wp-content directory.
volumes:
- .:/var/www/html/wp-content/
Put your theme in wp-content/themes. It should be exactly as if it where on server. Note: All the other wp default directory structure would be recreated on that mount point, and it will be persistent.
Edit: After chatting a bit, I understood what OP needed. In order to mount another dir from this architecture. You will need to point to the right path and mount it like this:
volumes:
- .:/var/www/html/wp-content/themes/testing:delegated
- ./plugins:/var/www/html/wp-content/plugins