DockerWordpressInstallOnDebian

Enter a topic name to show or a new topic name to create; then press Enter

Install Debian on Target Server

The steps to install Debian 8 (Jessie) are as follows:

  1. Download the Debian Network install image from https://www.debian.org/distrib/netinst selecting the amd64 option under Small CD section
  2. Burn a CD from the downloaded image
  3. Boot the Target Server from the created CD
  4. Install Debian following the prompts as required (choose LXDE and Utilities in the software options)

Install Utilities on Target Server

The utilities to be installed on the Server are:

  1. nginx web server for a reverse proxy
apt-get install nginx
  1. curl and apt-transport-https for getting software
apt-get install curl apt-transport-https
  1. Install MySQL Workbench using Synaptic

Configure nginx

In the directory /etc/nginx copy the file default to default.orig in the directory /etc/nginx/sites-available and paste the contents of the configuration file below. Then stop and restart nginx.

cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.orig
server {
    listen 80;
    server_name www.valcom.ca;
    location / {
	proxy_pass http://172.17.0.3:80;
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection 'upgrade';
	proxy_set_header Host $host;
	proxy_cache_bypass $http_upgrade;
    }
}
service nginx stop
service nginx start

Install Docker and Docker-Compose

The 2 docker related packages are:

  1. docker
  2. docker composer

The installation of docker (http://www.docker.io) is done by following the steps below:

apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
deb https://apt.dockerproject.org/repo debian-jessie main

for LXLE the values used are

deb https://apt.dockerproject.org/repo ubuntu-trusty main

apt-get update
apt-cache policy docker-engine
apt-get install docker-engine
curl -L https://github.com/docker/compose/releases/download/1.5.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version

NOTE: All commands that start with docker must be run as root user or preceeded by sudo

Copy an Existing Wordpress Docker Container Set

if you do not have an existing Docker Container Set then follow the instructions in the section Configure Docker Containers for Use below. If you do have a container set then copy the directory wp_docker to the location you want to run the docker set from. Verify that the paths in the volume settings of the file docker-compose.yml match your location

web:
      image: wordpress
      links:
       - mysql
      environment:
       - WORDPRESS_DB_PASSWORD=valcom
       - VIRTUAL_HOST=www.valcom.ca
      ports:
       - 8080:80
      working_dir: /var/www/html
      volumes:
       - /<your location>/wp-content:/var/www/html/wp-content
mysql:
      image: mysql
      environment:
       - MYSQL_ROOT_PASSWORD=valcom
       - MYSQL_DATABASE=wp01
       - MYSQL_USER=wp01User
       - MYSQL_PASSWORD=valcom
      volumes:
       - /<your location>/mysql_data:/var/lib/mysql

Configure Docker Containers for Use

Create a directory wp_docker in /root/Downloads and create a file docker-compose.yml with the contents below:

mkdir /home/valcom_web/wp_docker
touch /home/valcom_web/wp_docker/docker-compose.yml
web:
      image: wordpress
      links:
       - mysql
      environment:
       - WORDPRESS_DB_PASSWORD=valcom
      ports:
       - 8080:80
      working_dir: /var/www/html
      volumes:
       - /home/valcom_web/wp_docker/wp-content:/var/www/html/wp-content
mysql:
      image: mysql
      environment:
       - MYSQL_ROOT_PASSWORD=valcom
       - MYSQL_DATABASE=wp01
       - MYSQL_USER=wp01User
       - MYSQL_PASSWORD=valcom
      volumes:
       - /home/valcom_web/wp_docker/mysql_data:/var/lib/mysql

Move MySQL Data for Use

Move Wordpress Data for Use

Run the MySQL and Wordpress install

cd /home/valcom_web/wp_docker
docker-compose up -d

Fix Permissions for Wordpress

In the same directory as that which you started docker run the following command to ensure write permissions are working

chmod -R 764 wp-content
cd wp-content
chusr -R www-data .
chgrp -R www-data .

Shutdown Wordpress and MySQL

The following commands will shutdown wordpress and MySQL

docker stop wpdocker_web_1
docker stop wpdocker_mysql_1

Run MySQL Docker Container Alone

If the MySQL docker container is not running as part of the Wordpress execution it is still possible to run it alone using the following command

docker run --name mysql -v /home/valcom_web/wp_docker/mysql_data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=valcom -d mysql:5.5

The standalone MySQL docker container is stopped and removed using the following command (no data is lost).

docker rm -f mysql

Configure MySQL Workbench

Troubleshoot docker installation

This introduces some of the docker troubleshooting commands

Review docker container network properties

docker inspect wpdocker_mysql_1
docker inspect wpdocker_web_1

Determine running docker containers

docker ps

Determine all defined docker containers

docker ps -a

Show docker container logfiles

docker logs wpdocker_mysql_1
docker logs wpdocker_web_1

Connect to a mysql instance running inside a docker container

The command below starts a bash session in the container

docker exec -it wpdocker_mysql_1 bash

then issue a mysql command to connect to the mysql server in the container

mysql -u root -p --host 172.17.0.2

after that you will be in a mysql session on the command line

Problems with mysql connections

Somewhere in mysql 5.6 the permission for a user that granted access on localhost failed when the mysql instance was running on an internal network. The message for what the failure was did not get corrected until the latest version of mysql 5.7. In order to correct connection issues it may be necessary to issue a grant command using either "MySQL" Workbench or by executing a mysql command directly on the instance

grant all privileges on wp01.* to 'wp01User'@'172.17.0.3' identified by 'valcom';

Where wp01 is the wordpress database name, wp01User is the wordpress user and 172.17.0.3 is the ip address of the web (not the mysql) container.


Version: 29   Revised: 2016-05-17 19:04:38 Last Updated by: 2001:470:b0ad:1:8196:d83:dcd8:872f Rename Show Links to Topic