I'm setting up WordPress using Docker and I've hit a snag. I'm trying to keep track of my `wp-content/index.php` file in Git, but every time I run `docker-compose up`, it gets overwritten with the default content. My local directory structure looks like this:
```
wp-content/
├── plugins/
├── themes/
└── index.php
.env
.gitignore
docker-compose.yml
wp-config.php
```
In my `docker-compose.yml`, I'm only mounting the `wp-content` directory and a couple of other specific files, but when the container starts, it seems to reset `index.php` to its default state. The logs imply that WordPress is checking if it needs to install itself, but it respects the existing plugins and themes. How do I stop it from overwriting my `wp-content/index.php` file?
4 Answers
Instead of just mounting `wp-content`, consider mounting the whole WordPress directory. You could update your volumes in the `docker-compose.yml` to something like `- ./wp-content:/var/www/html/wp-content` and then make sure to include a volume for the entire application, like `- ./your_wordpress_directory:/var/www/html`. That way, your custom files get priority.
The issue is that you're only mounting the `wp-content` directory, so when the container starts up, it thinks WordPress isn't fully installed. It tries to set things up and overwrites files like `index.php`. You need to mount the entire WordPress installation, or you could specifically mount the `index.php` file too. This way, it won’t overwrite it on startup.
If you're still having issues even after changing the volumes, there are tons of ways to handle this. You could try editing the entry point script if you’re up for a bit of customization.
And just a side note, your environment section in the Compose file seems a bit redundant. Most of those variables are already set in the Docker images directly. You might want to streamline that.
Related Questions
How To Get Your Domain Unblocked From Facebook
How To Find A String In a Directory of Files Using Linux