SlideShare a Scribd company logo
Dockerizing WordPress
Requirements
• In order to complete this tutorial, you should make sure that
you have docker installed. For more information about
installation please visit the Docker website:
http://docs.docker.io/en/latest/
• You should also be familiar with the dockerfile instructions
covered in the dockerfile tutorial:
http://www.docker.io/learn/dockerfile/
• In addition to WordPress, we first need to install Apache,
MySQL and PHP inside our container. To keep this presentation
straightforward all these different software will be install in one
single docker container
• Throughout this tutorial I use docker with Vagrant and a
VirtualBox VM on a Mac computer. To get Docker and
WordPress running, the first step is to edit our Vagrantfile
with the line in red here below:
Computers-MacBook-Air:~ communityPC$ cd docker
Computers-MacBook-Air:docker communityPC$ emacs Vagrantfile

# Setup virtual machine box. This VM configuration code is
always executed.
config.vm.box = BOX_NAME
config.vm.box_url = BOX_URI
config.vm.forward_port 80, 8880
• Now that we have specified in our Vagrantfile that accessing
"localhost:8080" will access port 80 on the guest machine, we
can start the VM. We see that our change here below in red
has been taken into consideration
Computers-MacBook-Air:docker communityPC$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] -- 80 => 8880 (adapter 1)
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- /vagrant
• The following command will SSH into our running VM and give
us access to a shell
Computers-MacBook-Air:docker communityPC$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.8.0-29-generic x86_64)
* Documentation: https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 20 20:56:40 2013 from 10.0.2.2

• At this point it is important to become “root” to have
permission to start a container
vagrant@precise64:~$ sudo su
root@precise64:/home/vagrant#
• Lets create a new directory to proceed with our WordPress
installation
root@precise64:/home/vagrant# mkdir wordpress
root@precise64:/home/vagrant# cd wordpress
root@precise64:/home/vagrant/wordpress#

• We are now ready to open emacs and build our Dockerfile

root@precise64:/home/vagrant/wordpress# emacs Dockerfile
• So this is how our finished Dockerfile looks like. Note that the lines starting with
# are comments that give explanation about what will happen when building a
docker container from that Dockerfile
# Install LAMP stack and Wordpress
# use the latest ubuntu image
FROM ubuntu:12.04

MAINTAINER: Victor Coisne “victor.coisne@dotcloud.com"
# make sure the package repository is up to date
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
# install apache, mysql, php, emacs, wget and wordpress
RUN apt-get install -y mysql-server mysql-client
RUN apt-get install -y apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1
libdbd-mysql-perl libdbi-perl libnet-daemon-perl libplrpc-perl libpq5 mysql-common php5-common php5-mysql
RUN apt-get install -y emacs23 wget
# download the lastest version of wordpress and move the sources to the default apache serveur host /var/www
RUN wget http://wordpress.org/latest.tar.gz && mv latest.tar.gz /var/www

# Setting ports to be publicly exposed when running the image (Wordpress uses ports 80)
EXPOSE 80

If you are not comfortable with the Dockerfile syntax, follow this link http://www.docker.io/learn/dockerfile/
• It is now time to build our container from the current directory
and use the option -t to give it a name: wordpresstuto
root@precise64:/home/vagrant/wordpress# docker build -t wordpresstuto .

• Now that we have built our container lets run it !
root@precise64:/home/vagrant/wordpress# docker run -i -t -p 80:80
wordpress_tuto /bin/bash
root@bd4b8fdbd37f:/#

• –p 80:80 tells docker to forward port 80 from the container to
the VM and connect to that VM on the same port 80. Since we
are running the host OS inside Vagrant, the Vagrantfile that we
have modified will forward that back to port 8880 on our main
system.
• Note that port 80 should not be already in use. You can enter the
following command to be sure that there are no other processes
listening upon port 80:
Root@precise64:/home/vagrant/wordpress# lsof -Pni4 | grep LISTEN
rpcbind 680
root 8u IPv4 948 0t0 TCP *:111 (LISTEN)
rpc.statd 726
statd 9u IPv4 8180 0t0 TCP *:48561 (LISTEN)
sshd
761
root 3u IPv4 9607 0t0 TCP *:22 (LISTEN)
memcached 930 memcache 26u IPv4 9989 0t0 TCP 127.0.0.1:11211 (LISTEN)
dnsmasq 962 lxc-dnsmasq 7u IPv4 10007 0t0 TCP 10.0.3.1:53 (LISTEN)
.

• As you can see there are no processes listening upon port 80.
If there are any, you first have to kill them if you want to run
your docker container and forward port 80 from the container
to the host.
• Lets now go to the directory /var/www that is the location of
the website files
root@bd4b8fdbd37f:/# cd /var/www
root@bd4b8fdbd37f:/var/www#

• Now that we are in the /var/www we can unzip the latest
version of Wordpress downloaded in our dockerfile and found
on http://codex.wordpress.org/UNIX_Shell_Skills
root@bd4b8fdbd37f:/var/www# tar zxf latest.tar.gz

• The following command allow us to edit Apache’s default
configuration file
root@bd4b8fdbd37f:/var/www# emacs /etc/apache2/sites-enabled/000-default
• Inside that file we just have to change the Documentroot and
Directory lines as you can see here below in red
File Edit Options Buffers Tools Help
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/wordpress
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/wordpress/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
• MFirst let’s start the MySQL database
root@bd4b8fdbd37f:/var/www# /usr/sbin/mysqld &

• Let’s now start the Apache2 service
root@bd4b8fdbd37f:/var/www# /etc/init.d/apache2 start

• It is now time to change directory to edit the Wordpress
configuration file
root@bd4b8fdbd37f:/var/www# cd wordpress
• At this point, if we go to the following url in our web browser:
http://localhost:8880/ we see the following message
• As a result we just have to move our config-sample.php file to
a newly created wp-config.php file that Wordpress needed to
get started
root@bd4b8fdbd37f:/var/www/wordpress# mv wp-config-sample.php wpconfig.php

• Then we log in the mysql monitor as a “root” user
root@bd4b8fdbd37f:/var/www/wordpress# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 7
Server version: 5.5.22-0ubuntu1 (Ubuntu)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be
trademarks of their respective owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql>
• Let’s start by creating the database we need to run WordPress
and give it a name
mysql> create database victor_wordpress ;
Query OK, 1 row affected (0.00 sec)

• It is now time to create a new user name and password prior to
grant permissions to that user for the specific database we have
just created. Once this is done we simply reload all the privileges
and exit the MySQL shell
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password’ ;
mysql> GRANT ALL PRIVILEGES ON victor_wordpress.* TO 'newuser’ @'localhost’ ;
mysql> FLUSH PRIVILEGES ;
mysql> exit
Bye

• Lets now edit the configuration file using emacs
root@bd4b8fdbd37f:/var/www/wordpress# emacs wp-config.php
Now that we are inside the configuration file, lets edit the mysql
settings with the information previously defined in red here
below: database name, username and password
//** The name of the database for WordPress */
define('DB_NAME', 'wordpress_victor');
//** MySQL database username */
define('DB_USER', 'newuser');
//** MySQL database password */
define('DB_PASSWORD', 'password');
//** MySQL hostname */
define('DB_HOST', 'localhost');
• Now enter the following url in your favorite web browser: http://localhost:8880
Voilà ! You are now ready to start the Wordpress installation process.

• Wait there is one more thing to do …
• Don’t forget to share your work with the Docker community. To
do so we can push your container on the Docker index to store
the filesystem state and make it available for re-use.
• In order to push it on the Docker index, you first have to sign up:
https://index.docker.io/account/signup/
• So we first have to exit our container and go back to our host
root@bd4b8fdbd37f:/var/www/wordpress# exit
exit
There are stopped jobs.
root@bd4b8fdbd37f:/var/www/wordpress# exit
Exit
root@precise64:/home/vagrant/wordpress#
• We can use the following Docker command to find the ID of
our image (it should be the first one of the list)
root@precise64:/home/vagrant# docker ps -a
ID
IMAGE
COMMAND
bd4b8fdbd37f
wordpresstuto:latest /bin/bash

CREATED
STATUS
11 minutes ago
Exit 0

• Now that we have the ID we can commit the changes we have
made to the image and tag it using your username from the
Docker index / the name of your image. Our image is now
ready to be pushed to the docker index !
root@precise64:/home/vagrant/wordpress# docker commit bd4b8fdbd37f -t
vcoisne/wordpresstuto
93ed51f82520
root@precise64:/home/vagrant/wordpress# docker push vcoisne/wordpresstuto

• You can read more about Docker and WordPress here:
Slumlord hosting with Docker - WordPress Container
Want to learn more ?
http://www.docker.io/news_signup/
https://twitter.com/docker/
https://github.com/dotcloud/docker
http://stackoverflow.com/search?q=docker
https://botbot.me/freenode/docker/#
https://groups.google.com/forum/#!forum
/docker-user
https://plus.google.com/u/1/communities/
108146856671494713993
https://www.facebook.com/docker.run

More Related Content

PPTX
Installing and running Postfix within a docker container from the command line
PPTX
PHP development with Docker
PDF
Getting instantly up and running with Docker and Symfony
PPTX
Deploying Symfony2 app with Ansible
PDF
Rally_Docker_deployment_JumpVM
PDF
Docker perl build
KEY
DOCX
Dockerfish-Tutorial
Installing and running Postfix within a docker container from the command line
PHP development with Docker
Getting instantly up and running with Docker and Symfony
Deploying Symfony2 app with Ansible
Rally_Docker_deployment_JumpVM
Docker perl build
Dockerfish-Tutorial

What's hot (19)

PPTX
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
ODP
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
PPTX
PHP Dependency Management with Composer
PDF
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
PPTX
Dockerizing a Symfony2 application
PDF
Vagrant for real codemotion (moar tips! ;-))
PDF
Dockerize your Symfony application - Symfony Live NYC 2014
PDF
Docker use dockerfile
PDF
Light my-fuse
PPTX
Vagrant crash course
PDF
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
PPTX
PHP on Heroku: Deploying and Scaling Apps in the Cloud
PDF
JavaCro'15 - Conquer the Internet of Things with Java and Docker - Johan Jans...
PPTX
Composer | PHP Dependency Manager
PPTX
DevOps Hackathon - Session 1: Vagrant
PDF
App development with quasar (pdf)
PDF
Web development automatisation for fun and profit (Artem Daniliants)
PDF
Deploying WP Multisite to Heroku
PPTX
Deploying Windows Containers on Windows Server 2016
Dockerize Me: Distributed PHP applications with Symfony, Docker, Consul and A...
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
PHP Dependency Management with Composer
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
Dockerizing a Symfony2 application
Vagrant for real codemotion (moar tips! ;-))
Dockerize your Symfony application - Symfony Live NYC 2014
Docker use dockerfile
Light my-fuse
Vagrant crash course
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
PHP on Heroku: Deploying and Scaling Apps in the Cloud
JavaCro'15 - Conquer the Internet of Things with Java and Docker - Johan Jans...
Composer | PHP Dependency Manager
DevOps Hackathon - Session 1: Vagrant
App development with quasar (pdf)
Web development automatisation for fun and profit (Artem Daniliants)
Deploying WP Multisite to Heroku
Deploying Windows Containers on Windows Server 2016
Ad

Viewers also liked (20)

PPTX
Docker introduction
PPT
Integrating scientific laboratories into the cloud
PPTX
WordPress Development Environments
PDF
docker intro
PDF
Dockers y wp
PPTX
Docker in10mins
PDF
code.talks 2016 Hamburg - Plesk - AutoScaling WordPress with Docker & AWS - b...
PDF
Docker at Spotify - Dockercon14
PDF
Docker by Example - Basics
PPTX
John Engates Keynote at Dockercon 14
PDF
WordPress + Docker - Reusable WordPress development environments
PDF
Building a smarter application Stack by Tomas Doran from Yelp
PPTX
Immutable infrastructure with Docker and EC2
PDF
Михаил Боднарчук "Docker для PHP разработчиков"
PPTX
Installing and Running Postfix within a Docker Container
PDF
Architecting an Highly Available and Scalable WordPress Site in AWS
PPTX
Desenvolvendo para WordPress com Docker, Git e WP-CLI
PDF
Installing WordPress on AWS
PPTX
Docker and containers - For Boston Docker Meetup Workshop in March 2015
Docker introduction
Integrating scientific laboratories into the cloud
WordPress Development Environments
docker intro
Dockers y wp
Docker in10mins
code.talks 2016 Hamburg - Plesk - AutoScaling WordPress with Docker & AWS - b...
Docker at Spotify - Dockercon14
Docker by Example - Basics
John Engates Keynote at Dockercon 14
WordPress + Docker - Reusable WordPress development environments
Building a smarter application Stack by Tomas Doran from Yelp
Immutable infrastructure with Docker and EC2
Михаил Боднарчук "Docker для PHP разработчиков"
Installing and Running Postfix within a Docker Container
Architecting an Highly Available and Scalable WordPress Site in AWS
Desenvolvendo para WordPress com Docker, Git e WP-CLI
Installing WordPress on AWS
Docker and containers - For Boston Docker Meetup Workshop in March 2015
Ad

Similar to Dockerizing WordPress (20)

PPTX
Dockerizing WordPress
DOCX
A Manual for Setting up a WordPress Website on the Local Linux Server with Va...
PPTX
Vagrant WordCamp Hamilton
PDF
WordPress & Vagrant
PDF
PHP Project development with Vagrant
PDF
DevOps Camp 2017 NYC Local Development using Vagrant by Anthony Alvarez
PDF
Quick & Easy Dev Environments with Vagrant
PDF
Remote Control WordPress
PPTX
Install LAMP Stack in Linux Server OS and Hosting a Custom Domain .pptx
PDF
Take Home Your Very Own Free Vagrant CFML Dev Environment
PDF
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
PDF
Jones_Lamp_Tutorial
PDF
Wordpress y Docker, de desarrollo a produccion
PDF
Making Developers Productive with Vagrant, VirtualBox, and Docker
PDF
Preparation study of_docker - (MOSG)
PDF
The Themer's Guide to WP-CLI
PPTX
Vagrant and Docker
PPTX
How To Set a Vagrant Development System
PPTX
Vagrant-Overview
PDF
Keep calm and vagrant up
Dockerizing WordPress
A Manual for Setting up a WordPress Website on the Local Linux Server with Va...
Vagrant WordCamp Hamilton
WordPress & Vagrant
PHP Project development with Vagrant
DevOps Camp 2017 NYC Local Development using Vagrant by Anthony Alvarez
Quick & Easy Dev Environments with Vagrant
Remote Control WordPress
Install LAMP Stack in Linux Server OS and Hosting a Custom Domain .pptx
Take Home Your Very Own Free Vagrant CFML Dev Environment
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Jones_Lamp_Tutorial
Wordpress y Docker, de desarrollo a produccion
Making Developers Productive with Vagrant, VirtualBox, and Docker
Preparation study of_docker - (MOSG)
The Themer's Guide to WP-CLI
Vagrant and Docker
How To Set a Vagrant Development System
Vagrant-Overview
Keep calm and vagrant up

More from dotCloud (20)

PPTX
DockerCon Keynote Ben Golub
PDF
Are VM Passé?
PDF
OpenStack - Docker - Rackspace HQ
PDF
Docker in pratice -chenyifei
PDF
Wot2013云计算架构师峰会 -陈轶飞2
PDF
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
PDF
Introduction to Docker and all things containers, Docker Meetup at RelateIQ
PPTX
Introduction to dockerfile, SF Peninsula Software Development Meetup @Guidewire
PDF
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
PPTX
Dockerizing stashboard - Docker meetup at Twilio
PPTX
Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013
PDF
Dockerizing your applications - Docker workshop @Twitter
PDF
Introduction to Docker - Docker workshop @Twitter
PDF
Docker worshop @Twitter - How to use your own private registry
PDF
Docker links | Docker workshop #2 at Twitter
PPTX
Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05
PPTX
Intro Docker october 2013
PDF
[Open stack] heat + docker
PDF
Building images from dockerfiles
PPTX
Docker at DevTable
DockerCon Keynote Ben Golub
Are VM Passé?
OpenStack - Docker - Rackspace HQ
Docker in pratice -chenyifei
Wot2013云计算架构师峰会 -陈轶飞2
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
Introduction to Docker and all things containers, Docker Meetup at RelateIQ
Introduction to dockerfile, SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Dockerizing stashboard - Docker meetup at Twilio
Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013
Dockerizing your applications - Docker workshop @Twitter
Introduction to Docker - Docker workshop @Twitter
Docker worshop @Twitter - How to use your own private registry
Docker links | Docker workshop #2 at Twitter
Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05
Intro Docker october 2013
[Open stack] heat + docker
Building images from dockerfiles
Docker at DevTable

Recently uploaded (20)

PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
Teaching material agriculture food technology
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Understanding_Digital_Forensics_Presentation.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
Approach and Philosophy of On baking technology
Unlocking AI with Model Context Protocol (MCP)
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Spectral efficient network and resource selection model in 5G networks
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Weekly Chronicles - August'25 Week I
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Teaching material agriculture food technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

Dockerizing WordPress

  • 2. Requirements • In order to complete this tutorial, you should make sure that you have docker installed. For more information about installation please visit the Docker website: http://docs.docker.io/en/latest/ • You should also be familiar with the dockerfile instructions covered in the dockerfile tutorial: http://www.docker.io/learn/dockerfile/ • In addition to WordPress, we first need to install Apache, MySQL and PHP inside our container. To keep this presentation straightforward all these different software will be install in one single docker container
  • 3. • Throughout this tutorial I use docker with Vagrant and a VirtualBox VM on a Mac computer. To get Docker and WordPress running, the first step is to edit our Vagrantfile with the line in red here below: Computers-MacBook-Air:~ communityPC$ cd docker Computers-MacBook-Air:docker communityPC$ emacs Vagrantfile # Setup virtual machine box. This VM configuration code is always executed. config.vm.box = BOX_NAME config.vm.box_url = BOX_URI config.vm.forward_port 80, 8880
  • 4. • Now that we have specified in our Vagrantfile that accessing "localhost:8080" will access port 80 on the guest machine, we can start the VM. We see that our change here below in red has been taken into consideration Computers-MacBook-Air:docker communityPC$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... [default] Setting the name of the VM... [default] Clearing any previously set forwarded ports... [default] Creating shared folders metadata... [default] Clearing any previously set network interfaces... [default] Preparing network interfaces based on configuration... [default] Forwarding ports... [default] -- 22 => 2222 (adapter 1) [default] -- 80 => 8880 (adapter 1) [default] Booting VM... [default] Waiting for VM to boot. This can take a few minutes. [default] VM booted and ready for use! [default] Mounting shared folders... [default] -- /vagrant
  • 5. • The following command will SSH into our running VM and give us access to a shell Computers-MacBook-Air:docker communityPC$ vagrant ssh Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.8.0-29-generic x86_64) * Documentation: https://help.ubuntu.com/ Welcome to your Vagrant-built virtual machine. Last login: Fri Sep 20 20:56:40 2013 from 10.0.2.2 • At this point it is important to become “root” to have permission to start a container vagrant@precise64:~$ sudo su root@precise64:/home/vagrant#
  • 6. • Lets create a new directory to proceed with our WordPress installation root@precise64:/home/vagrant# mkdir wordpress root@precise64:/home/vagrant# cd wordpress root@precise64:/home/vagrant/wordpress# • We are now ready to open emacs and build our Dockerfile root@precise64:/home/vagrant/wordpress# emacs Dockerfile
  • 7. • So this is how our finished Dockerfile looks like. Note that the lines starting with # are comments that give explanation about what will happen when building a docker container from that Dockerfile # Install LAMP stack and Wordpress # use the latest ubuntu image FROM ubuntu:12.04 MAINTAINER: Victor Coisne “victor.coisne@dotcloud.com" # make sure the package repository is up to date RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list RUN apt-get update # install apache, mysql, php, emacs, wget and wordpress RUN apt-get install -y mysql-server mysql-client RUN apt-get install -y apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libdbd-mysql-perl libdbi-perl libnet-daemon-perl libplrpc-perl libpq5 mysql-common php5-common php5-mysql RUN apt-get install -y emacs23 wget # download the lastest version of wordpress and move the sources to the default apache serveur host /var/www RUN wget http://wordpress.org/latest.tar.gz && mv latest.tar.gz /var/www # Setting ports to be publicly exposed when running the image (Wordpress uses ports 80) EXPOSE 80 If you are not comfortable with the Dockerfile syntax, follow this link http://www.docker.io/learn/dockerfile/
  • 8. • It is now time to build our container from the current directory and use the option -t to give it a name: wordpresstuto root@precise64:/home/vagrant/wordpress# docker build -t wordpresstuto . • Now that we have built our container lets run it ! root@precise64:/home/vagrant/wordpress# docker run -i -t -p 80:80 wordpress_tuto /bin/bash root@bd4b8fdbd37f:/# • –p 80:80 tells docker to forward port 80 from the container to the VM and connect to that VM on the same port 80. Since we are running the host OS inside Vagrant, the Vagrantfile that we have modified will forward that back to port 8880 on our main system.
  • 9. • Note that port 80 should not be already in use. You can enter the following command to be sure that there are no other processes listening upon port 80: Root@precise64:/home/vagrant/wordpress# lsof -Pni4 | grep LISTEN rpcbind 680 root 8u IPv4 948 0t0 TCP *:111 (LISTEN) rpc.statd 726 statd 9u IPv4 8180 0t0 TCP *:48561 (LISTEN) sshd 761 root 3u IPv4 9607 0t0 TCP *:22 (LISTEN) memcached 930 memcache 26u IPv4 9989 0t0 TCP 127.0.0.1:11211 (LISTEN) dnsmasq 962 lxc-dnsmasq 7u IPv4 10007 0t0 TCP 10.0.3.1:53 (LISTEN) . • As you can see there are no processes listening upon port 80. If there are any, you first have to kill them if you want to run your docker container and forward port 80 from the container to the host.
  • 10. • Lets now go to the directory /var/www that is the location of the website files root@bd4b8fdbd37f:/# cd /var/www root@bd4b8fdbd37f:/var/www# • Now that we are in the /var/www we can unzip the latest version of Wordpress downloaded in our dockerfile and found on http://codex.wordpress.org/UNIX_Shell_Skills root@bd4b8fdbd37f:/var/www# tar zxf latest.tar.gz • The following command allow us to edit Apache’s default configuration file root@bd4b8fdbd37f:/var/www# emacs /etc/apache2/sites-enabled/000-default
  • 11. • Inside that file we just have to change the Documentroot and Directory lines as you can see here below in red File Edit Options Buffers Tools Help <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/wordpress <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/wordpress/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory>
  • 12. • MFirst let’s start the MySQL database root@bd4b8fdbd37f:/var/www# /usr/sbin/mysqld & • Let’s now start the Apache2 service root@bd4b8fdbd37f:/var/www# /etc/init.d/apache2 start • It is now time to change directory to edit the Wordpress configuration file root@bd4b8fdbd37f:/var/www# cd wordpress
  • 13. • At this point, if we go to the following url in our web browser: http://localhost:8880/ we see the following message
  • 14. • As a result we just have to move our config-sample.php file to a newly created wp-config.php file that Wordpress needed to get started root@bd4b8fdbd37f:/var/www/wordpress# mv wp-config-sample.php wpconfig.php • Then we log in the mysql monitor as a “root” user root@bd4b8fdbd37f:/var/www/wordpress# mysql -u root Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 7 Server version: 5.5.22-0ubuntu1 (Ubuntu) Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql>
  • 15. • Let’s start by creating the database we need to run WordPress and give it a name mysql> create database victor_wordpress ; Query OK, 1 row affected (0.00 sec) • It is now time to create a new user name and password prior to grant permissions to that user for the specific database we have just created. Once this is done we simply reload all the privileges and exit the MySQL shell mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password’ ; mysql> GRANT ALL PRIVILEGES ON victor_wordpress.* TO 'newuser’ @'localhost’ ; mysql> FLUSH PRIVILEGES ; mysql> exit Bye • Lets now edit the configuration file using emacs root@bd4b8fdbd37f:/var/www/wordpress# emacs wp-config.php
  • 16. Now that we are inside the configuration file, lets edit the mysql settings with the information previously defined in red here below: database name, username and password //** The name of the database for WordPress */ define('DB_NAME', 'wordpress_victor'); //** MySQL database username */ define('DB_USER', 'newuser'); //** MySQL database password */ define('DB_PASSWORD', 'password'); //** MySQL hostname */ define('DB_HOST', 'localhost');
  • 17. • Now enter the following url in your favorite web browser: http://localhost:8880 Voilà ! You are now ready to start the Wordpress installation process. • Wait there is one more thing to do …
  • 18. • Don’t forget to share your work with the Docker community. To do so we can push your container on the Docker index to store the filesystem state and make it available for re-use. • In order to push it on the Docker index, you first have to sign up: https://index.docker.io/account/signup/ • So we first have to exit our container and go back to our host root@bd4b8fdbd37f:/var/www/wordpress# exit exit There are stopped jobs. root@bd4b8fdbd37f:/var/www/wordpress# exit Exit root@precise64:/home/vagrant/wordpress#
  • 19. • We can use the following Docker command to find the ID of our image (it should be the first one of the list) root@precise64:/home/vagrant# docker ps -a ID IMAGE COMMAND bd4b8fdbd37f wordpresstuto:latest /bin/bash CREATED STATUS 11 minutes ago Exit 0 • Now that we have the ID we can commit the changes we have made to the image and tag it using your username from the Docker index / the name of your image. Our image is now ready to be pushed to the docker index ! root@precise64:/home/vagrant/wordpress# docker commit bd4b8fdbd37f -t vcoisne/wordpresstuto 93ed51f82520 root@precise64:/home/vagrant/wordpress# docker push vcoisne/wordpresstuto • You can read more about Docker and WordPress here: Slumlord hosting with Docker - WordPress Container
  • 20. Want to learn more ? http://www.docker.io/news_signup/ https://twitter.com/docker/ https://github.com/dotcloud/docker http://stackoverflow.com/search?q=docker https://botbot.me/freenode/docker/# https://groups.google.com/forum/#!forum /docker-user https://plus.google.com/u/1/communities/ 108146856671494713993 https://www.facebook.com/docker.run

Editor's Notes

  • #9: Explain that port 80 should not be already in use otherwiselsof -Pni4 | grep LISTEN