1

I'm currently working on a project using the WordPress API.

This is my docker-compose.yml file:

version: '3.1'

services:
  wordpress:
    image: wordpress
    volumes:
      - ./volumes/wordpress/:/var/www/html
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_PASSWORD: root
    depends_on:
      - mysql

  mysql:
    image: mysql:5.7
    volumes:
      - ./volumes/mysql/:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root

  web:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./src/:/src
    ports:
      - 8081:8081
    depends_on:
      - wordpress

In order to use the WordPress API, I need to configure the WordPress container manually by going to http://localhost:8080/wp-admin and changing some settings.

Thing is, I need to make this settings changes automatic because everytime I remove the volume folder in order to reset the WordPress content, it also removes the settings.

Any idea on how I can achieve this?

2 Answers 2

2

I guess that all settings configured via the wp-admin section are stored in the database.

If that's the case than you can do this:

  1. Setup a first WordPress instance by running your docker-compose and completing the setup steps.
  2. Stop the compose. At this point in the mysql volume folder you have a database structure with a configured wordpress in it.
  3. Store the contents of the folder somewhere.

Now, if you want to create another WordPress instance, you can edit the docker-compose.yml file in order to adjust volume binding and make sure that the initial content of the mysql volume contains the data you got from step 3 above.

When you start the new docker-compose stack it'll start from a populated database and you should have a preconfigured WordPress instance.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. You are right indeed, the settings are stored in the database. I've made a dump the first the docker-compose up ran and then use it in my docker-compose.yml file to provide the initial settings.
0

You need to locate the file/folder that containes the settings that you are changing.

Start the container, do the changes and backup the settings file into your host machine using:

docker cp <container-name>:<path-to-settings> .

You then can create a custom image that replaces the default settings with the backuped settings you copied to the host.

FROM wordpress
COPY <settings-from-host> <settings-path-in-container>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.