Skip to content
This repository was archived by the owner on May 29, 2023. It is now read-only.

Build and run

Dimitrios Desyllas edited this page Aug 22, 2017 · 2 revisions

Build and run

Introduction

We will show various recommended methods to run this image. All methods below MUST require to have installed the docker.

Building

Building without docker compose

In order to build it use theese steps:

git clone git@github.com:ellakcy/wordpressWithPlugins.git
cd wordpressWithPlugins
# Build for alpine & fpm image
docker build --tag ^a name for your container^ -f Dockerfile  --no-cache .
# Build for apache image
docker build --tag ^a name for your container^ -f Dockerfile_apache  --no-cache .

Using docker-compose

In order to build it use theese steps:

git clone git@github.com:ellakcy/wordpressWithPlugins.git
cd wordpressWithPlugins
# Build for alpine & fpm image
docker-compose build --no-cache wordpress
# Build for apache image
docker-compose build --no-cache wordpress_apache

Alternatively you can use the ellakcy/wordpressswithplugins for a default image.

Running

The image extends the default wordpress image and has some extra enviromental variables.

  • WORDPRESS_ADMIN_USERNAME (default: admin) That is the username of the admin user
  • WORDPRESS_ADMIN_PASSWORD (default: admin123) That is the password of the admin user. PLEASE DO CHANGE WHEN ON PRODUCTION.
  • WORDPRESS_ADMIN_EMAIL (default:admin@example.com) The administrator email. (Recomended to change.)
  • WORDPRESS_URL (default: localhost) Your site's url. PLEASE LOOK THE EXAMPLES BELOW.
  • WORDPRESS_TITLE (default: 'My localhost site') The title to be displayed when generating the site.

For more about the default enviromental variables look https://hub.docker.com/_/wordpress/

Furgermore this repo provides theese 2 variations of a wordpress image image:

1 alpine-fpm: That is based on wordpress:php7.0-fpm-alpine

2 apache: That is bases on wordpress:php7.0-apache

Run the image

Run apache-bases image

Without docker-compose

Run a container for the database:

docker run --name ^a name^ -e MYSQL_ROOT_PASSWORD=^a super strong password^ --volume ^some volume name^:/var/lib/mysql -d mariadb

And then the image itself:

docker run --name ^an another name^ --link ^a name^:mysql -e WORDPRESS_URL=http://0.0.0.0:8080 -e WORDPRESS_DB_PASSWORD=^a super strong password^ --volume ^a volume name^:/var/www/http -p 8080:80 -d ^autogenerated hash from docker build or the tag^

Note: Where _^autogenerated hash from docker build or the tag^_ can also use the name of the image uploaded on docker hub (ellakcy/wordpressswithplugins:apache).

Υου can visit the freshly installed wordpress by visiting http://0.0.0.0:8080 or http://localhost:8080 to your browser, it is recommended to clear your browser's cache first if no result is seen.

Without docker-compose with an internal network

First of all create a custom network.

docker create network --ip-range=172.12.0.0/19 ^network_name^

(You can modify the ip range as you please)

After run a container for the database:

docker run --name ^a name^ --net ^network_name^ --ip 172.12.0.2 -e MYSQL_ROOT_PASSWORD=^a super strong password^ --volume ^some volume name^:/var/lib/mysql -d mariadb

And then the image itself:

docker run --name ^an another name^ --net ^network_name^ --ip 172.12.0.2 --link ^a name^:mysql -p 8080:80 -e WORDPRESS_URL=172.12.0.3 -e WORDPRESS_DB_PASSWORD=^a super strong password^ --volume ^a volume name^:/var/www/http -d ^autogenerated hash from docker build or the tag^

Note: Where _^autogenerated hash from docker build or the tag^_ can also use the name of the image uploaded on docker hub (ellakcy/wordpressswithplugins:apache).

Υου can visit the freshly installed wordpress by visiting http://172.12.0.2 to your browser.

With docker-compose:

Because many installations especially the alpine-fpm based one needs more than 1 extra container is recomended to use docker-compose. For ease you can use one of the following docker-compose.yml.

If the correct docker-compose.yml has been generated the you can run docker-compose up -d to run them.

Also in the following examples the values that are in the $VAR form are values thet get replaced from an .env file. So you can either replaced with hardcoded values or generate a .env file with the following content:

WORDPRESS_MYSQL_USER="^mysql_username^"
WORDPRESS_MYSQL_PASSWORD="^mysql_password^"
WORDPRESS_ADMIN_USER="^wordprress_admin_username^"
WORDPRESS_ADMIN_PASSWORD="^wordpress_admin_password^"
WORDPRESS_URL="http://localhost:7070"

WORDPRESS_APACHE_URL="http://localhost:7071"

Also consult this for more info, keep in mind that the examples use syntax version 2.

docker-compose.yml for fpm image

version: '2'
services:
  nginx:
    image: nginx:alpine
    ports:
      - "7070:80"
    volumes:
      - './conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro'
    links:
      - "wordpress"
    volumes_from:
      - "wordpress:ro"
    environment:
      NGINX_PORT: "8080"

  wordpress-db:
    image: mariadb
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
      MYSQL_ONETIME_PASSWORD: "yes"
      MYSQL_DATABASE: "wordpress"
      MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
      MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'

  wordpress:
    image: ellakcy/wordpressswithplugins:alpine-fpm
    links:
      - wordpress-db
    environment:
        WORDPRESS_DB_HOST: wordpress-db:/var/run/mysqld/mysqld.sock
        WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
        WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
        WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
        WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
        WORDPRESS_URL: '${WORDPRESS_URL}'

docker-compose.yml for apache based image:

version: '2'
services:
  wordpress-apache-db:
    image: mariadb
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
      MYSQL_ONETIME_PASSWORD: "yes"
      MYSQL_DATABASE: "wordpress"
      MYSQL_USER: '${WORDPRESS_MYSQL_USER}'
      MYSQL_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'

  wordpress_apache:
    image: ellakcy/wordpressswithplugins:apache
    links:
      - wordpress-apache-db
    ports:
      - "7071:80"
    environment:
        WORDPRESS_DB_HOST: wordpress-apache-db:/var/run/mysqld/mysqld.sock
        WORDPRESS_DB_USER: '${WORDPRESS_MYSQL_USER}'
        WORDPRESS_DB_PASSWORD: '${WORDPRESS_MYSQL_PASSWORD}'
        WORDPRESS_ADMIN_USERNAME: '${WORDPRESS_ADMIN_USER}'
        WORDPRESS_ADMIN_PASSWORD: '${WORDPRESS_ADMIN_PASSWORD}'
        WORDPRESS_URL: '${WORDPRESS_APACHE_URL}'