Migrating Drupal and WordPress sites using Docker

November 13, 2015

There’s several sites I host for family and friends in addition to this site. It’s a mix of WordPress, Drupal, and static sites, all running on a Linux virtual host hosted by Rackspace. The Linux host is pretty old at this point, and really should be upgraded. Additionally, I wanted to give DigitalOcean a try as I can get a virtual server there for less.

Although I kept the installations for each site pretty well organized in different directories, migrating them over the traditional way would still be time consuming and error prone, involving copying over all the directories and databases that are needed, migrating users, making sure permissions are right, and making sure to get any service scripts and configurations that need to come along. This is all a very manual process. If (when) I get something wrong, I’d have to troubleshoot it on the target server, and the whole process isn’t very repeatable nor version controlled. I wasn’t looking forward to it.

While working on our Pilot product at Encanto Squared, a new tool came on our radar, Docker, which we adopted and greatly simplified and streamlined our deployment and server provisioning process at Encanto.

Naturally, I decided to use docker to migrate my sites to another server, and to generally improve how these are being managed.

The overall configuration looks like this:

rpsSitesDocker

The above diagram is inspired by this dockerboard tool. The tool works but the diagram required some style tweaking so I did it in OmniGraffle.

Each of the rounded rectangles above is a separate docker container, and all of the containers are orchestrated by docker compose. The blue lines between the containers are docker compose links, which connect the two containers at a network level, and create an entry in the source’s host file pointing to the target container. Each docker container runs with its own network, layered filesystem, and process space. So for one container to be able to communicate with another it has to be specifically enabled, via links in the case of docker compose.

Following is a breakdown of each container and its configuration:

nginx - front-end reverse proxy

[code lang=text] FROM nginx COPY conf.d /etc/nginx/conf.d [/code]

[code lang=text] server { listen 80; server_name www.mfyah.org mfyah.org;

location / { proxy_pass http://mfywordpress:80; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } [/code]

latinchristmas - This is a static site hosted by nginx

[code lang=text] FROM nginx

COPY WWW /usr/share/nginx/html [/code]

mfy - Wordpress-based site

[code lang=text] FROM wordpress

RUN apt-get update && apt-get install -y libcurl4-openssl-dev

RUN docker-php-ext-install curl [/code]

I won’t go into the other WordPress-based containers. They’re essentially the same.

DB - MariaDB

Docker compose and usage

As mentioned above, all of this is managed by Docker Compose. Following is a portion of the Docker Compose configuration file.

[code lang=text] latinchristmas: image: somedockerrepo/someuser/latinchristmaswebsite:latest restart: always

mfywordpress: image: somedockerrepo/someuser/mfy restart: always links: - db:mysql environment: WORDPRESS_DB_NAME: mfy volumes: - /var/lib/cont/mfywp:/var/www/html

db: image: mariadb restart: always environment: MYSQL_ROOT_PASSWORD: PutSomethingHere volumes: - /var/lib/cont/db:/var/lib/mysql

nginx: build: nginx restart: always ports: - “80:80” links: - latinchristmas - mfywordpress [/code]

The WordPress-based site images are stored on a Docker repository. The proxy nginx image is built locally by Docker Compose.

The steps I took to get this all working on the server were roughly:

Everything should be running at this point.

I haven’t converted over the Drupal sites yet, but the approach will be the same as the WordPress sites.

The benefits to this setup are:

Future improvements:

Tags: dockernginxwordpress