Wordpress on PhotonOS under Docker

We Live in the Cloud

WordPress on PhotonOS under Docker

1st October 2018 Docker Photon 0

To build upon my previous docker/photon post here, I wanted to move away from the theory and show you how you can download VMware’s Photon OS, install Docker, and then run a WordPress container to show it all in action.  It’s a simple process once you know how, but to get to this point, I spent a fair few hours playing and testing, so hopefully you can forgo all of that and skip to the good part!

You can read more about what Photon OS, Docker and Containers are in my previous post, so lets get started.

First of all we need to download PhotonOS using the link below.  Here we’re looking to use v2.0.  This can all be run from your desktop.  I recommend 4GB ram, 4CPU and selecting NAT when you import the OVA into VMware Workstation for PC or Fusion for Mac.

http://dl.bintray.com/vmware/photon/2.0/GA/ova/photon-custom-lsilogic-hw11-2.0-304b817.ova

Once downloaded, boot up the appliance to get you to the console.

Change root password

Login as root password changeme

Finding PhotonOS IP address

ip addr | grep eth0

 

Upgrade PhotonOS

We are going to download the latest PhotonOS components , enable Docker and reboot the VM

tdnf distro-sync

systemctl enable docker

 

Create a new User

Change username to your username

useradd -m -U username
passwd username
usermod -aG docker username

 

Reboot

init 6

 

Logging in

From this stage onwards I highly recommend you ssh in from a client using the username above (putty or just SSH in using terminal on Mac) eg ssh [email protected], as you can copy and paste the text below, something the console within Workstation or Fusion won’t allow.

Install Docker Compose

su -
curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
chgrp docker /usr/local/bin/docker-compose
exit

 

Create a wordpress template directory

This is a yaml directory to hold the wordpress build script

mkdir wordpress
cd wordpress

Now create the wordpress script

vi docker-compose.yml

 

Pick 2 passwords, 1 for the wordpress db password and 1 for the mysql root password, use a password with no symbols around 15 chars long, removing the brackets.  Once done exit out of vi as you normally would, committing the changes

version: '3.3'

services:
   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     volumes:
       - wordpress_files:/var/www/html
     ports:
       - "80:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: (wordpress_db_password)

   db:
     image: mysql:8
     command: '--default-authentication-plugin=mysql_native_password'
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: (mysql root password)
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: (wordpress db password)
volumes:
    wordpress_files:
    db_data:

You will notice that the two final lines create local directories on your Photon instance to store your WordPress and SQL files, enabling them to survive the container creation and destruction process.

Start WordPress Container

The first time this runs it will pull down the lastest Official WordPress Container as well as the latest MySQL Container

docker-compose up -d

 

Launch a web browser and continue the wordpress installation

http://(ip address of PhotonOS)

And that’s you done!  You should now have a version of WordPress running in a Docker container running on Photon OS.  Additional actions that you can do are:

Shutting down WordPress Container

docker-compose down

 

Upgrading WordPress Container to latest versions

docker-compose down

docker-compose pull

docker-compose up -d

 

Remove all WordPress Data

BE WARNED THIS WILL REMOVE ALL THE WORDPRESS AND MYSQL DATA VOLUMES

docker-compose down –volumes

 

Please note that due to the nature of containers, everything within the container will be destroyed when you shut this down which is why the data is held in volumes outside the container.