Docker Wordpress plugins persistence or mapping to local plugins

admin

Administrator
Staff member
I am running the latest Docker mac app and have created a new
Code:
docker-compose.yml
in my project directory. (which is my wordpress theme).

<a href=" " rel="nofollow noreferrer"><img src=" " alt=" "></a>

<br/>

This is my configuration
Code:
docker-compose.yml
file below...

Code:
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

<br/>

So far i'm finding it awesome. I had a few issues with getting the database to be persistent, and figuring out that
Code:
wp-content
folder needs the owner to be set to
Code:
www-data
.

But after fixing the above, it's working so good and if I
Code:
docker-compose down
and
Code:
up
my database is persistent. Plus my database is being pulled from my local theme.

<br/>

What lets it down is that my plugins folder resets itself if I
Code:
docker-compose down
or <br/>
Code:
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
Code:
docker-compose up -d
it remembers my plugins.

Any ideas would be awesome.

<br/>

For example I could put the plugins folder in my local theme folder project...

<a href=" " rel="nofollow noreferrer"><img src=" " alt="enter image description here"></a>

<br/>

<hr>

<strong>SOLVED!</strong>

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
Code:
plugins
and
Code:
uploads
to version control or my staging server environment. These are purely here for my local persistent data incase I
Code:
docker-compose down
.

See my phpStorm project structure now...

<a href=" " rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TPBp3.png" alt="enter image description here"></a>

See my
Code:
docker-compose.yml
config file...

Code:
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

<br/>

Thanks <a href="https://stackoverflow.com/users/11703041/ludi-sistemaš">@Ludi Sistemaš</a> for your help.

<br/>