How to Manually Build Docker Containers for WordPress

Originally published at: http://www.sitepoint.com/how-to-manually-build-docker-containers-for-wordpress/

In the first article, we covered what Docker is and how to get up and running with a few commands. However, we haven’t done anything useful just yet. There are numerous ways to get a WordPress environment using Docker, in this article, I’ll show you how to manually setup Docker containers to work with WordPress. If you’d like a quick intro into Docker, you can jump back to the first article here.

Setting up MySQL

Every WordPress installation needs a MySQL database. To do this, we head over to Docker Hub and find a MySQL image.

The Docker team already has a MySQL image ready for us to use. Before running any commands on the terminal, make sure to read the documentation for this image. The latest version at the time of writing is 5.7. However, the latest tag name is 5.6. The latest version of an image can be for any previous version, but one in its stable state.

Continue reading this article on SitePoint
1 Like

That all seems MUCH more complex than just using puphpet.com. Maybe it is just me though. Not to mention how would one install extensions, pear packages, node, ruby, gems, etc. Using puphpet that is just a matter of clicking checkboxes. Using this it involves MUCH more it seems. You’re not really selling me on this as it looks SO much more complex than using puphpet.com. I’m really failing to see the benefit here over puphpet.com where it is merely configure your box through a UI and run vagrant up for *most things. Not to mention the list of supported technologies keeps growing and growing with “one click” installs. Here you would have to go digging to find them on the hub and cross your fingers they all work when put together in the same container.

Hi @oddz . Glad to see that you are following these articles. Yes I agree that Docker is a bit complex
. But in the next article things will get very easy. I did this complex article to show how Docker works underlying. But there are tools (Docker-Compose) that makes things very easy. Also not to mention official images. More on this in the next article. There is also one last article on how to deploy this on DigitalOcean so stay tuned if you haven’t gave up already :smile: .

If you are using Vagrant than it is a good thing because Vagrant (PuPHPet) are not very used on PHP community. Community is adopting Vagrant but there is more road ahead. Docker is a new cool tool and yet complex. But will be a lot easier when it evolves more.

I would agree that without puphpet.com vagrant would be just as complex. However, until there is a tool like puphpet.com for docker it just seems like a lot of work that could be eliminated using puphpet.com. Establishing a proficient workflow to run ANY site on a local environment is something I have heavy interest in. However, I haven’t found much wrong with the puphpet one. I hear amazon will also be releasing a “container” service so I wonder how that will compare to docker.

It seems like if you’re afraid of the command line you’re afraid of the command line and that is it. Anyone who is afraid of the command line just reverts back to *amp. Which is all fine and dandy until you need ALL the other things a larger enterprise level ecosystem requires in terms of dependencies and dev tools.

Amazon has released it’s container support for Docker. I have tested it a bit and I found really good for the first release. But I also find Amazon services hard to work. They need a lot a lot of work.

At least now PuPHPet is stable enough. I year ago it was a really mess.

I’m really glad you mentioned the “fear from command line” syndrome (that’s how I call it). I think it is a real syndrome. After all it is on the hands of the developer if he/she wants to use it. There are a lot of things that can be done a lot faster via terminal (CMD) than GUI based tools. Knowing terminal (*nix systems), makes everyone a better developer because that way, you will know better how things work.

For example, today I was working with a package for PHP that can make testing cookies with PhpUnit a reality and had to install a bunch of PECL packages. And it was a very very messed up job with terminal. I took some hours off because I got stucked on terminal without finding a way out. Will get again back to find a solution. I learned a lot even from failures on terminal. Things that I wouldn’t learn normally.

A couple of months ago I wrote an article about Vagrant VVV (wordpress configuration) and It got really crazy on the comments. Now 52 comments and growing every month. The disquisition wasn’t for VVV although. It was a huge debate on why using terminal was wrong and good. Take a few minutes and read the comments on this article: http://www.sitepoint.com/wordpress-meets-vagrant-vvv/ . I guaranty that you will enjoy it :smile: .

This sums up my thoughts on that.

The thing is though most the Wordpress folk don’t know how to program so I’m not terribly surprised with that answer. Wordpress caters to designers and content editors not programmers. I mean solutions like Drupal have been nearly COMPLETELY modernized but Wordpress is still running on the same antiquated, procedural mess it was running on a decade ago and it still is being used in abundance. So it just goes to show the importance programming and modernization in that ecosystem. It ain’t at all an ecosystem you become involved in because of code quality but simply chugging out a editable site as fast as you can with minimal actual, programming involved.

I have also that problem with WordPress. It is old architecture. I prefer more to code with Laravel because it promotes good code and architecture. A group of developers released also a CMS based on Laravel (October CMS). I saw it a bit today and I found that coding for CMS is a bit pain. Even a CMS backed by Laravel gets really messy. There are developers that like to work with CMS and other that don’t. It’s preference after all.

But let’s agree that WordPress also does it job very well for most people. The real pain is for developers. As a developer you would want to start a theme from scratch. Dealing with others code (themes) is a pain because everyone does it in different way.

I also wasn’t surprised a lot with the topic, but some responses really got my attention. Like that one for example. Not just from non terminal guys, but from terminal guys also.

Great article!! For Those who think using docker command line is a cumbersome task, you can use Kitematic GUI tool for Docker. It is an awesome tool for setting up your dev environment using Docker. Only downside is that , it is availbale only for MAC now.

probably a baic question but

After this bit

docker run --name wordpress -v “$PWD/”:/var/www/html php:5.6-apache

how do I access this in my browser?

I am using windows/cygwin/boot2docker

I can do this:

docker@boot2docker:~$ curl 172.17.0.8/hello.php

But from cygwin when I do this I get nothing

curl 192.168.59.103/hello.php

I’m having the same issue, but I doubt it is OS related because I’m using a Mac. When I try to pull up the IP in a browser no connection. Same thing when I curl and ping the IP.

Okay, I got it working. I hope these notes help the next person.

The goal is to access the PHP info page served by Apache using your host Mac or PC’s web browser. If you can’t ping, curl or browse the IP given in the apache log I’ve found your solution. Also, if you can’t find the folder or having permission problems this might help.

##Problems

  • Port 80 not maped to Apache IP that defaults to port 80.
  • Apache can’t find the index.php file.
  • Apache report you don’t have permission to view index.php.

##Solution

First, delete the wordpress images you created.

docker rm wordpress

Then get your boot2docker ip address.

boot2docker info

Now create your index.php file in your index.php CURRENT directory.

  • the tutorial was not clear that Apache is configured to use /var/www/html. The PWD command is a shortcut to map your CURRENT path to the Apache’s html directory. It appears the tutorial assumes we all create files in our home folders…

I suspect you COULD replace "$PWD/" with "/a/valid/absolute/folder/path/" if you wanted to. Windows, users. You will probably need a valid windows path if you go down this route. I stuck with using "$PWD/" since I will not be using this image for production.

Now map your boot2docker port 80 to apache with -p 80:80 like this.

docker run -p 80:80 --name wordpress -v “$PWD/”:/var/www/html php:5.6-apache

Congrats! Assuming you created the index.php in your computer’s home directory where you have valid permissions, you will get a beautiful php info page.

nice to know about docker theme and it is a paid template or free one? free means can apply in my site also

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.