Slowly dockerizing my WP site – HTTP server “in a box”

So after 4 years of using a bare-metal dedicated server where I would manually configure every single thing, I decided that it was time to move on. I was paying more than I was using and a potential migration to a new server would take hours / days to configure again.

Just before I pull the plug, I spinned an EC2 amazon instance and started thinking how I could make that work. I needed a way to have everything ready in minutes. So I went with docker. Docker would help me have the 3 main wordpress components packaged and configured in no time. The DB (just MySQL), the files and the HTTP server. I also needed a way to deploy things fast. Should I go with Ansible? Should I go with Terraform? I didn’t need a configuration management tool, I needed an orchestration tool but at the same time I didn’t want to over complicate things.

I understand that the Internet is full of HOW-to guides on how to dockerize a WP site and how to use docker-compose for that job. There is even an official docker image for wordpress. I needed something simple and modular.

I slowly started preparing a HTTP docker container that would respect my wordpress caching configurations and would also support SSL (Let’s encrypt). So I went with nginx. Nobody ever complained about nginx :). Nginx will serve the supercache generated static files much faster than apache. My wordpress configuration and file structure is pretty plain, so the Nginx docker container would have to be as generic as possible so that anyone can re-use it.

And here is it: https://github.com/alexballas/php-fpm-nginx-wp-super-cache-docker
The repo name is bad, i know..

And a simple example:

$ git clone https://github.com/alexballas/php-fpm-nginx-wp-super-cache-docker.git
$ cd php-fpm-nginx-wp-super-cache-docker
$ sudo docker build -t mynginx .
$ mkdir -p www
$ echo "This is a test HTML file" > www/test.html
$ sudo docker run --name nginx -it -d -p 80:80 -p 443:443 -v `pwd`/www:/var/www/html mynginx
$ curl http://localhost/test.html
This is a test HTML file

So the HTTP part is ready. The only issue I had with it so far, were the incorrect file permissions. This is a known docker issue when using volumes and the host machine UIDs don’t match the container’s UIDs.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on RedditShare on TumblrShare on LinkedInEmail this to someone