Deploying WordPress

This tutorial demonstrates how to deploy the official WordPress Docker image to the Apcera Platform using two approaches:

The tutorial is optimized for Community Edition (CE). See the Enterprise Edition (EE) section if you are using it.

Deploy WordPress using manifest

The following multi-resource manifest will run without modification on Community Edition.

{
    "jobs": {
        "job::/sandbox/admin::myblog": {
            "docker": {
                "image": "library/wordpress:latest"
            },
            "exposed_ports": [ 80],
            "routes": [
                {
                    "type": "http",
                    "endpoint": "auto",
                    "config": {
                        "/": [ { "weight":100, "port":80 } ]
                    }
                }
            ],
            "services":{
                "egress": {
                    "fqn": "service::/apcera::outside"
                },
                "mysql-wordpress": {
                    "fqn": "service::/sandbox/admin::myblog-mysql"
                },
                "var-www-html": {
                    "fqn": "service::/sandbox/admin::wordpress-www-html",
                    "params": {
                        "mountpath": "/var/www/html"
                    }
                }
            },
            "env": {
                "WORDPRESS_DB_HOST":
                "{{ (binding_service \"myblog-mysql\").URI.Host }}:{{ (binding_service \"myblog-mysql\").URI.Port }}",
                "WORDPRESS_DB_USER":
                "{{ (binding_service \"myblog-mysql\").URI.User }}",
                "WORDPRESS_DB_PASSWORD":
                "{{ (binding_service \"myblog-mysql\").URI.Password }}",
                "WORDPRESS_DB_NAME":
                "{{ (binding_service \"myblog-mysql\").URI.TrimmedPath }}"
            },
            "state": "started"
        }
    },
    "services": {
        "service::/sandbox/admin::myblog-mysql": {
            "description": "Database for myblog wordpress",
            "name": "myblog-mysql",
            "provider_fqn": "provider::/apcera/providers::mysql-provider",
            "type": "mysql"
        },
        "service::/sandbox/admin::wordpress-www-html": {
            "description": "NFS storage for blog files",
            "name": "wordpress-www-html",
            "provider_fqn": "provider::/apcera/providers::apcfs",
            "type": "nfs"
        }
    }
}

To deploy the manifest

  1. Copy the contents of the above manifest to a text file named wordpress-manifest.json.

  2. Log in to the web console for your platform.

    Or target your cluster and log in using APC.

  3. Click Launch > Manifest and upload the wordpress-manifest.json file.

    Or run apc manifest deploy wordpress-manifest.json.

  4. Check the Logs tab to tail the job logs and view job status.

    Or run apc job logs myblog. (Use "control+c" to stop tailing the logs.)

  5. Select the Networking tab and click the up arrow to the right of the route endpoint to launch WordPress.

    Or run apc job show myblog and copy the route URL to a browser.

    The WordPress "Welcome" page should appear where you can create an admin profile and install WordPress. Note that it may take up to 2 minutes for the WordPress container to copy the necessary files and be ready to access.

Deploy WordPress using APC

The following APC command uses runtime variables to parse the required DB parameters and deploy a WordPress Docker job.

apc docker run myword -i wordpress -e 'WORDPRESS_DB_HOST={{ (binding_service "myword-mysql").URI.Host }}:{{ (binding_service "myword-mysql").URI.Port }}' -e 'WORDPRESS_DB_USER={{ (binding_service "myword-mysql").URI.User }}' -e 'WORDPRESS_DB_PASSWORD={{ (binding_service "myword-mysql").URI.Password }}' -e 'WORDPRESS_DB_NAME={{ (binding_service "myword-mysql").URI.TrimmedPath }}' --routes http://myword.<mycluster>.apcera-platform.io --port 80 --provider /apcera/providers::apcfs --no-start

To deploy Wordpress using APC

  1. Copy the above APC command to a text file.

  2. Change the <mycluster> token in the --routes URL to match your cluster subdomain.

  3. Target your cluster and log in using APC.

  4. Run the updated command using APC.

    Be sure to include the --no-start flag so that you do not start WordPress. (You will this after binding the job to MySQL.)

  5. Create MySQL service.

     apc service create myword-mysql --provider /apcera/providers::mysql-provider
    
  6. Bind the WordPress job to the MySQL service.

     apc service bind myword-mysql -j myword
    
  7. Start the WordPress job.

     apc job start myword
    
  8. Check the job logs to see the status and troubleshoot.

     apc job logs myword
    
  9. Launch WordPress.

    The WordPress "Welcome" page should be accessible at the --routes URL, such as http://myword.mycluster.apcera-platform.io. Use apc job show to get the route URL. Note that it may take up to 2 minutes for the WordPress container to copy the necessary files and be ready to access.

Enterprise Edition

The tutorial is optimized for Community Edition (CE). If you are using the Enterprise Edition, the configuration differs slightly, and you will need to verify that your cluster has the required policy and providers.

Prerequisites

You need policy permissions to deploy Docker jobs and bind them to MySQL and NFS services. The following policy lets you pull Docker images from the public DockerHub. See the policy documentation for additional policy examples for jobs and services.

on job::/ {
    { docker.allow "*"}
}

WordPress requires MySQL DB for site data and a persistent volume for file storage. To deploy WordPress, you need the following providers registered with the cluster:

Provider FQN Descrption
NFSv4 provider::/apcera/providers::apcfs If you do not have the apcfs NFSv4 provider, talk to your cluster admin.
MySQL provider::/apcera/providers::mysql If you do not have a MySQL provider, you can create one using the MySQL Docker image.

To verify that you have these providers in your cluster, go to the Providers page in the web console, or run apc providers list -ns /. Note the FQN for each if different from above.

Deploy WordPress to EE using manifest

Complete the manifest deployment steps with the following modifications:

  • Name the manifest file wordpress-manifest-ee.json.
  • Change all occurrences of the namespace sandbox/admin to match your namespace.
  • If necessary, change the MySQL provider FQN (/apcera/providers::mysql-provider) to match yours (such as /apcera/providers::mysql or /sandbox/NAME::mysql-provider).
  • If necessary, change the NFS provider FQN (/apcera/providers::apcfs) to match yours (such as /apcera/providers::nfs-sandbox).

Deploy WordPress to EE using APC

Complete the APC deployment steps with the following modifications (if necessary):

  • Change the NFS provider FQN (/apcera/providers::apcfs) to match yours (such as /apcera/providers::nfs-sandbox).
  • Change the MySQL provider FQN (/apcera/providers::mysql-provider) to match yours (such as /apcera/providers::mysql or /sandbox/NAME::mysql-provider).
  • Update the myword name token in the --routes URL so that the route is unique in the cluster.

Create MySQL provider

If you don't have a MySQL provider, or if you want to create one in your namespace, you can deploy the official MySQL Docker image as a job backed by NFS for persistence.

To do this, run the following APC commands:

apc docker run mysql --restart always --image mysql --tag 5.7.11 --port 3306 --provider /apcera/providers::apcfs  --env-set MYSQL_ROOT_PASSWORD=password
apc provider register mysql-provider --job mysql -u mysql://root:password@mysql-server

To verify that you successfully created the provider, in the web console go to the Providers screen, or use the APC command apc providers list -ns /. Note that once created the FQN for this provider will typically be provider::/sandbox/NAME::mysql-provider.