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

FreeNAS Error Creating Pool

command '('gpart', 'create', '-s', 'gpt', '/dev/da8')' returned non-zero exit status 1. If you get this error while trying to create… Read More

May 14, 2019 8:22 am 08:22

Change Grub Default Boot Entry on Linux Mint

i'm dual booting windows and linux mint on my laptop. the grub default is to boot into linux mint, however… Read More

April 23, 2019 7:45 pm 19:45

How to Reset Secure Channel On Active Directory Domain Controller

when you're a little too careless about virtualizing your domain controllers, cloning, migrating, backing up and restoring, returning from vacation… Read More

April 21, 2019 8:14 am 08:14

Run SystemD Script Before System Shutdown

for the sheer hell of it, a few weeks ago i wanted to see if i could properly and successfully… Read More

April 20, 2019 10:14 am 10:14

Learn Systemctl Usage to Manage Systemd Service in Linux

systemd is new service manager for linux. it's a replacement for all previous init systems (sysv/sysvinit & ubuntu's upstart) and… Read More

April 20, 2019 7:55 am 07:55

Force Delete Windows Server DHCP Failover Relationship

if you've found yourself here then chances are you messed up one of your domain controllers or at least one… Read More

April 20, 2019 5:54 am 05:54