How to Migrate WordPress Nginx with Docker Compose on Ubuntu Xenial 16.04

This guide will explain how to migrate and dockerize an existing WordPress installation without running Apache. Most other tutorials I've seen combine multiple services inside of one container, while this article tries to maintain the standard of one service per container for easier isolation, troubleshooting, performance, and scale-out. This consists of configuring multiple Docker containers with docker-compose on Ubuntu 16.04 Xenial to run MariaDB 10.0.31 or MySQL, Nginx 1.13, PHP7.1-FPM and WordPress 4.8.

There are many tutorials for creating new WordPress sites with Docker containers such as this one, however there aren't many for those who already have a site and want to migrate existing WordPress installations to Docker containers.

Directory structure:

/docker
├── nginx_proxy
├── nginx_src
│   ├── conf.d
│   ├── h5bp
│   ├── sites-available
│   ├── sites-enabled
│   └── ssl
├── php_fpm
│   └── 7.0
├── wp_compose
├── wp_content
│   └── src
├── wp_img
│   └── src
└── wp_db
├── etc
└── var

Install Docker

Use official Docker Installation or use the code below to install since the version in the standard repo's are dated.

wget -qO- https://get.docker.com/ | sh
#or
sudo curl -fsSL get.docker.com | sh

Backup WordPress

First step is to backup your MySQL database and Tar your WordPress wp-content directory. Unlike most DB backup tutorials, this creates the database if it does not exist with the -B switch. My WordPress Docker image (wp_img) contains the rest of the files of the latest version. This site will help if you don't have the ability to create a backup but do have the database files.

#Backup wordpress db
mysqldump -u [user] -p -B -h [hostname] [database] --triggers --routines > ~/wordpress.sql
#Backup wp-content
tar -cvzf ~/wp-content.tar.gz /var/www/html/wp-content
#Or backup entire site directory
tar -cvzf ~/wp-full.tar.gz /var/www/html

Dockerfile wp_db

FROM mariadb:10.0
ADD *.sql /docker-entrypoint-initdb.d/
ADD *.sh /docker-entrypoint-initdb.d/

The official MariaDB/MySQL Docker images will execute .sh, .sql and .sql.gz files in the containers /docker-entrypoint-initdb.d directory, which contains the wordpress.sql backup file along with any shell scripts.

Build and Run wp_db

docker build . -t sysinfo-io:mariadb10.0
docker run -d -e MYSQL_RANDOM_ROOT_PASSWORD=yes -p 3306:3306 -v /docker/wp_db/var:/var/lib/mysql -v /docker/wp_db/etc:/etc/mysql/conf.d --name wp_db -t sysinfo-io:mariadb10.0
To access the shell inside of a running container: docker exec -it <container-name> bash
Share
Disqus Comments Loading...

Recent Posts

VMWare vSphere 6.7 ESXTOP Output Garbled

If your VMWare vSphere 6.x environment command output of esxtop looks like a bunch of garbled gibberish (it's actually CSV… Read More

February 28, 2019 7:39 pm 19:39

How To Run RoboCopy Backup in Parallel

From time to time Windows Admins will surprise you with band-aid and bubble gum scripts, that's entirely expected I think.… Read More

February 28, 2019 12:20 pm 12:20

Windows 10 GodMode - The Ultimate Administrator Shortcut

Have you ever wondered what life might be like if the Windows 10 OS somehow had a single folder that… Read More

February 28, 2019 7:58 am 07:58

Samsung Galaxy S9 G960/G965 Stock ROM Firmware Download

There could be any number of reasons for needing to flash manufacturer stock OEM firmware on a Samsung Galaxy S9… Read More

January 24, 2019 7:42 am 07:42

Output IP Address with ipconfig Findstr Ethernet Adapter

How many times have you entered  ipconfig /all at the command line to return a single IP address, then have to strain… Read More

January 20, 2019 12:39 am 00:39

AWS SES Assistance in Enterprise Market - A Must Read

Designing e-mail solutions on a large scale can be a complex and costly challenge for a business: you need to… Read More

December 25, 2018 4:01 pm 16:01