Docker_WordPress

Docker_WordPress

We are going to setup the WordPress site with ubuntu image.

 

Host setting:

CentOS Linux release 7.1.1503 (Core)
Linux rhel7 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
 

Prerequisite of host server:

  • Docker must installed.

You can check using below command.

[root@rhel7 ~]# docker –version

Docker version 1.12.6, build 88a4867/1.12.6

 

Then pull Ubuntu image for a lab setup.

# docker pull ubuntu

Check docker image downloaded or not.
# docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
docker.io/ubuntu                        latest              ea4c82dcd15a        11 days ago         85.85 MB

 

Now start two containers with ubuntu image.

  • First for web application with port map 82 to 80 and
  • second for database with port map 3306 to 3306.
# docker run -it –name ubuntu_apache -p 82:80 docker.io/ubuntu
# docker run -it –name ubuntu_mysql -d  -p 3306:3306 docker.io/ubuntu

 

Check docker process are start and running.

[root@rhel7 ~]# docker ps -a

CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                   PORTS                    NAMES
0b834a2e1484        docker.io/ubuntu                       "/bin/bash"              3 hours ago         Up 3 hours               0.0.0.0:3306->3306/tcp   ubuntu_mysql
c92a3e450ca1        docker.io/ubuntu                       "/bin/bash"              13 days ago         Up 5 hours               0.0.0.0:82->80/tcp       ubuntu_apache

Here you can see port configuration.

0.0.0.0:3306->3306/tcp   and  0.0.0.0:82->80/tcp

 

Now configure web application container.

Login to web application container with below command.

List “CONTAINER ID“

[root@rhel7 ~]# docker ps -a
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                   PORTS                    NAMES
0b834a2e1484        docker.io/ubuntu                       "/bin/bash"              3 hours ago         Up 3 hours               0.0.0.0:3306->3306/tcp   ubuntu_mysql
c92a3e450ca1        docker.io/ubuntu                       "/bin/bash"              13 days ago         Up 5 hours               0.0.0.0:82->80/tcp       ubuntu_apache

Here we can see “CONTAINER ID” of “ubuntu_apache” is “c92a3e450ca1”.

 

Now login into the container.

[root@rhel7 ~]# docker exec -it c92a3e450ca1 bash

Now we have prompt look like “root@c92a3e450ca1:/#”.

 

Next we install all Prerequisite(Apache, PHP, PHP-Mysql) in ubuntu container.

root@c92a3e450ca1:/# apt-get update
root@c92a3e450ca1:/# apt install apache2
root@c92a3e450ca1:/# apt-get install php libapache2-mod-php php-mysql php-pear php-fpm

 

Check apache is accessible on port “82” or not.

  root@c92a3e450ca1:/# service apache2 restart

Access URL on the browser.

 

Now deploy WordPress source code in the container.

Copy WordPress zip file to container.

# docker cp  wordpress-4.9.8.tar.gz  c92a3e450ca1:/var/www/html/

Then login into container and unzip source code.

[root@rhel7 ~]# docker exec -it c92a3e450ca1 bash
                root@c92a3e450ca1:/# cd /var/www/html
root@c92a3e450ca1:/# gunzip wordpress-4.9.8.tar.gz
root@c92a3e450ca1:/# tar xvf wordpress-4.9.8.tar

 

Now configure Database container.

Log in to Database container with below command.

List “CONTAINER ID“

[root@rhel7 ~]# docker ps -a
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                   PORTS                    NAMES
0b834a2e1484        docker.io/ubuntu                       "/bin/bash"              3 hours ago         Up 3 hours               0.0.0.0:3306->3306/tcp   ubuntu_mysql
c92a3e450ca1        docker.io/ubuntu                       "/bin/bash"              13 days ago         Up 5 hours               0.0.0.0:82->80/tcp       ubuntu_apache

Here we can see “CONTAINER ID” of “ubuntu_mysql” is “0b834a2e1484”.

Now login into a container.

[root@rhel7 ~]# docker exec -it 0b834a2e1484 bash

Now we have prompt look like “root@0b834a2e1484:/#”.

 

Next, we install all Prerequisite(Mysql) in ubuntu container and configure it.

root@0b834a2e1484:/# apt-get update
root@0b834a2e1484:/# apt install mysql-server

 

Add this line to access MySql in a network or on IP.

root@0b834a2e1484:/# cat /etc/mysql/my.cnf
[mysqld]
bind-address    = 0.0.0.0

 

Now start MySql service and configure it.

root@0b834a2e1484:/# service mysql restart

 

To set root account password and other setting

root@0b834a2e1484:/# mysql_secure_installation 

 

Now login into a database. After that create one database with user access to setup WordPress site.

Here database is “feenix” user is “bnm” and password is “Redhat@12345

root@0b834a2e1484:/# mysql -u root -p
Enter password:
mysql> create database feenix;
mysql> grant all privileges on *.* to 'bnm'@'%' identified by 'Redhat@12345';
mysql> FLUSH PRIVILEGES;
mysql> commit;

 

Now again restart Mysql service.

root@0b834a2e1484:/# service mysql restart

 

In a web application container.

Now right time to update database information in WordPress “wp-config-sample.php”.

root@c92a3e450ca1:/# cd /var/www/html/wordpress/
root@c92a3e450ca1:/# vim wp-config-sample.php

 

 

Make a copy of “wp-config-sample.php” with a name of “wp-config.php”

root@c92a3e450ca1:/# cp  wp-config-sample.php wp-config.php

Now access URL on the browser. We have WordPress installation page which indicates web application server successfully communicate with a database server.  

 

After installation, we have a new WordPress website.

 

Leave a Reply

Your email address will not be published. Required fields are marked *