Docker Tutorial: WordPress
It’s no secret that we love Docker here, but if you’re not familiar with Docker, you may be asking yourself one question: why? There are many, many reasons, including the official images! We here at InfoSiftr might be slightly biased, but we think that most of the official images are pretty cool – not only that, but they are incredibly easy to use as well! To show how easy the official images are to use, let’s go through and set up a running instance of WordPress from scratch! With Docker and their official images, this really is as simple to do as running a few commands!
To start off, we need a container running the MySQL database that WordPress will use to store all its information. While there are a lot of different configurations you can use, the basic, out of the box instance of MySQL from the official images library is sufficient to get started.
docker pull mysql:latest
This step is pretty straight-forward: the docker client will go and fetch the latest mysql image. Then, all you need to do is run the image in a new container, give it an easy name to remember, and set the instance’s root password.
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=qwerqwer -d mysql
Here, we start a container, name it `some-mysql`, and then set an environment variable called `MYSQL_ROOT_PASSWORD` to `qwerqwer` inside the container, and then run the mysql image we downloaded in the last step. Bam! We have our database up, running, and waiting for us to connect it to WordPress.
Getting WordPress up and running is as easy as it was getting our MySQL instance up, via the `docker pull` and `docker run` command. First thing’s first – we need to fetch WordPress from Docker’s official images.
docker pull wordpress:latest
Just like the database example, this command will go and fetch the latest official wordpress image. Then, all we need to do is run the image in a new container, link our mysql image to it, and expose the port Apache httpd is listening on inside the container to the outside world!
docker run --name wordpress-instance --link some-mysql:mysql -p 8080:80 -d wordpress
So, we named our running container `wordpress-instance`, linked it to our mysql container, and mapped port 8080 on the host to port 80 inside the container (the default port Apache httpd listens on), and now our wonderful, fresh installation of WordPress should be exposed to the world! If you’re running this on a local machine, you should now be able to visit `localhost:8080` in your browser and see a shiny, running instance of WordPress! If you are using boot2docker on Mac or Windows just run `boot2docker ip` and use the displayed IP address instead of localhost; for example: `192.168.59.103:8080`.
By Talon Bowler
Sr. Software Developer
To follow up with Talon, please email us at [email protected]
InfoSiftr is a premier container solutions provider, global authority in development and management of container images, and offers professional programming services to deliver custom solutions. InfoSiftr has leading experts in microservices native infrastructures and is a certified training partner of Docker and provider for all of their solutions.