Where is my Docker WordPress Website Storing Data?

I currently have a WordPress container set up in Docker, and have it linked to a MySQL database on the same machine (that is not in a Docker container). I played around with editing the website in my browser, deleting the WordPress container, and creating a new one linked to the same database.

When I did this, the sample posts I made on my website persisted, so I assumed my data was being stored by my database locally. However, I then tried setting up multiple websites using WordPress Multisite using one WordPress container. To do this, I had to edit the WordPress config file inside the WordPress container.

Read More

I deleted this container, and created a new one like before. I tried replicating the config changes in this container, however, when I navigate to my website, it just gives me a white screen. This leads me to think that the MySQL database is pointing to empty tables all of a sudden.

Where are my WordPress templates/info actually being stored?

EDIT: Below is the command I run

sudo docker run -p 80:80 --name wordpress_local -e WORDPRESS_DB_HOST=(machine's IP address) -e WORDPRESS_DB_USER=user -e WORDPRESS_DB_PASSWORD=password -d wordpress

Note: This is assuming I have a local MySQL database set up that accepts connections from 0.0.0.0 and has a user called user with password password

I know that my container is properly linking to the database from looking at the logs (and the fact that I can access the website–just get a blank page)

EDIT 2: Looking at my WordPress container filesystem, I can navigate different folders and do see content such as themes/plugins that I have installed. Why is this not being stored on my local machine? (Sorry if this is a dumb question–I am new to both MySQL and Docker)

Related posts

1 comment

  1. When you run wordpress container for the first time, the initialization script downloads the wordpress codebase to /var/www/html and then start the web server. Since everything inside a container is ephemeral, the codebase with any changes you make will be lost when you re-run the container (unless you just stop/start the container which is not the best option for this scenario).

    What you need is to make this folder have persistent data. To achieve this you have to mount a folder from the host machine inside the container:

    sudo docker run -p 80:80 
       --name wordpress_local 
      -e WORDPRESS_DB_HOST=(machine's IP address) 
      -e WORDPRESS_DB_USER=user 
      -e WORDPRESS_DB_PASSWORD=password 
      -d 
      -v `pwd`/html:/var/www/html 
      wordpress
    

    Don’t forget, the folder should be already created: mkdir -p data

Comments are closed.