Wordpress

In this example, we'll deploy Wordpress tool with its MariaDB database.

1. Create shared variables

Go to "Environment variables" menu and create this variable.

  • MY_WORDPRESS_DB_PASSWORD (don't forget to check the "hide value" box)

2. Create Wordpress and MariaDB services

services:
  - id: wp
    name: myWP
    dockerConfiguration:
      image: wordpress
      imageVersion: latest
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 80
        healthCheckEnabled: false
        loadBalancerRules:
          - publicPort: 443
    links:
      - toServiceId: db
        toServicePort: 3306
        variableHost: MY_DB_HOST
        variablePort: MY_DB_PORT
        variableAddress: MY_DB_ADDRESS
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
    environmentVariables:
      - key: WORDPRESS_DB_HOST
        value: "%MY_DB_ADDRESS%"
      - key: WORDPRESS_DB_USER
        value: "wp"
      - key: WORDPRESS_DB_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: WORDPRESS_DB_NAME
        value: "wp"
  - id: db
    name: myDB
    dockerConfiguration:
      image: mariadb
      imageVersion: "11.0"
    countMin: 1
    countMax: 1
    ports:
      - listeningPort: 3306
        healthCheckEnabled: false
    capacityCpuMhz: 1024
    capacityMemoryMB: 512
    sharedEnvironmentVariables:
      - MY_WORDPRESS_DB_PASSWORD
    environmentVariables:
      - key: MYSQL_RANDOM_ROOT_PASSWORD
        value: "yes"
      - key: MYSQL_USER
        value: "wp"
      - key: MYSQL_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
      - key: MYSQL_DATABASE
        value: "wp"
      - key: DB_HOST
        value: "MY_DB_HOST"
      - key: DB_PORT
        value: "MY_DB_PORT" 
      - key: DB_NAMES
        value: "wp" 
      - key: DB_USER
        value: "wp" 
      - key: DB_PASSWORD
        value: "%MY_WORDPRESS_DB_PASSWORD%"
In this example, we create both services with a single import, but you can import them in several steps.

Here is the section allowing communication between services:

links:
  - toServiceId: db
    toServicePort: 3306
    variableHost: MY_DB_HOST
    variablePort: MY_DB_PORT
    variableAddress: MY_DB_ADDRESS

This block instructs LayerOps that our WordPress service should be able to communicate with another service with id "db" on port 3306. In addition to creating the link, this block is used to inject environment variables into our wordpress service:

  • MY_DB_HOST: will contains the host to access service db (example: 127.0.0.1)
  • MY_DB_PORT: will contains the port to access service db (example: 9000)
  • MY_DB_ADDRESS: will contains the address to access service db (example: 127.0.0.1:9000)

Then, to indicate which address our Wordpress should use to communicate with the database, we add the WORDPRESS_DB_HOST environment variable.

environmentVariables:
  - key: WORDPRESS_DB_HOST
    value: "%MY_DB_ADDRESS%"
Check WORDPRESS_DB_HOST and other environment variables documentation