Docker Community Forums

Share and learn in the Docker community.

Migrating Wordpress site to docker creates fresh installation

I am new to Docker and I am trying to migrate my existing wordpress site from to docker with in the same server. I am using nginx proxy for the frontend connection. however when I run my docker-compose and access the site I am getting a fresh installation page. Below is my docker-compose config,

version: ‘3.6’

image: mysql:{MYSQLDB_VERSION} container_name: mysql command: --default-authentication-plugin=mysql_native_password restart: always environment: - MYSQL_ROOT_PASSWORD={MYSQL_ROOT_PASSWORD}
- 3306:3306
- ./database/data:/var/lib/mysql
- ./mysql_config:/tmp/mysql_config

- mysql
restart: always
image: wordpress:{WORDPRESS_VERSION} container_name: wordpress volumes: - {WORDPRESS_DATA_DIR}:/var/www/html

image: nginx:{NGINX_VERSION:-latest} container_name: nginx ports: - '80:80' - '443:443' volumes: - {NGINX_CONF_DIR}:/etc/nginx/conf.d
- {NGINX_LOG_DIR}:/var/log/nginx - {WORDPRESS_DATA_DIR}:/var/www/html
- wordpress
restart: always

Can someone help in validating this config and let me know where I am going wrong.

This is a new installation, so you can’t expect anything else. The next step is to create a backup of you original site (for example with UpdraftPlus) an restore it into the container.
(Btw, I didn’t check your config.)

@tekki, Appreciate your response on this.

I did create a dump of my mysql in .sql format and stored in the directrory ./database/data/.
Thats where I used the volume in docker-compose file “- ./database/data:/var/lib/mysql”
but still it starts with a new installation.

Any further thoughts on this.

Step 1: Understanding Docker Compose
In the last post, we used the direct docker --run command but since we’ll be dealing with more than one container, it’ll be much easier to work with docker-compose.

Docker compose is a tool used to configure several containers at once. From the official documentation

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you create and start all the services from your configuration.

To update (or install) your docker version to the latest one and install docker-compose, you can run the following command.

wget -O -| bash
With docker-compose, we will define a single docker-compose.yml file for our entire stack.

Step 2: Export the WordPress site
Before you start moving your WordPress site, it is usually a good idea to deactivate all plugins first.

We need the following things from the current site.

A zip archive of the entire contents of the WordPress site. (I’ll refer to this as
A dump of the MySQL database. (I’ll refer to this as database.sql)
The database name. (I’ll refer to this as example_db_name)
The database password. (I’ll refer to this as example_db_password)
The database user. (I’ll refer to this as example_db_user)
Once you have them, place them in the root of your current site. i.e and

Step 3: Set up the site source code
Make sure the /var/www/ folder is empty, then create an src/ folder inside it to contain our site code. You can do both of those with the following commands

rm -r /var/www/*
mkdir -pv /var/www/
Now we will download the site archive we created to our site.

cd /var/www/
wget “” --no-check-certificate
Next we will unzip the archive into the src folder

unzip -d src/
Now, we should have our WordPress site code fully copied to our server

Step 4: Set up the site database
WordPress requires a database to work, and since we want to keep our data, we’ll store the data in a directory volume which we will mount unto our docker container.

Next, we’ll create the folder /var/www/ to contain our database data and configuration.

mkdir -pv /var/www/
We will store our database data inside the database/data folder, so we create it using the following command

mkdir -pv /var/www/
The MySQL container will execute any .sh, .sql or .sql.gz file in the /docker-entrypoint-initdb.d folder inside the container. So, we will place our sql dump into a folder and mount that into the /docker-entrypoint-initdb.d folder of the container.

mkdir -pv /var/www/
cd /var/www/
wget “” --no-check-certificate
Step 5: Start Docker containers using docker-compose
We will be using the official WordPress docker image to hold our code, and the official MySQL image for our database. To prepare the docker-compose, we’ll need to create a docker-compose.yml file

Now, we’ll create the docker-compose.yml file.

touch /var/www/
Edit docker-compose.yml and add the following

version: ‘2’

image: mysql:5.7
container_name: example_db
- ./database/data:/var/lib/mysql
- ./database/initdb.d:/docker-entrypoint-initdb.d
restart: always
MYSQL_ROOT_PASSWORD: aieububsnlVUOBWHLEINA # any random string will do
MYSQL_DATABASE: example_db_name # the name of your mysql database
MYSQL_USER: example_db_user # the name of the database user
MYSQL_PASSWORD: example_db_password # the password of the mysql user

- example_db
image: wordpress:php7.1 # we’re using the image with php7.1
container_name: example
- “1234:80”
restart: always
- example_db:mysql
- ./src:/var/www/html
We will bring up our docker containers using the docker-compose command.

To keep our site data safe, we will add Docker Volumes to the example and example_db services. This means that if we decide to take the container down, our site and data won’t be deleted.

cd /var/www/
docker-compose up -d
Step 6: Use Nginx as a reverse proxy to our Docker Container
Our Docker container is now running, but our site is not up just yet. Let us set up our Nginx configuration file for our website to serve content from within our docker container.

cd /etc/nginx/sites-available
Now edit and make it look like this.

server {
listen 80;
listen [::]:80;

location / {
    proxy_set_header Accept-Encoding "";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

Enable the site config so Nginx can load it

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
Reload Nginx for our configuration to take effect.

/etc/init.d/nginx reload

1 Like