mker9q
Last Updated: October 31, 2016
·
2.853K
· wstucco

Deploy WordPress using Docker and Dokku

Clone WP from github

git clone git@github.com:WordPress/WordPress.git app

Add this code to wp-config.php and commit it.

same technique can be used to configure the security keys, I didn't, to keep things short.

define('DB_NAME', getenv('WP_DB_NAME'));

/** MySQL database username */
define('DB_USER', getenv('WP_DB_USER'));

/** MySQL database password */
define('DB_PASSWORD', getenv('WP_DB_PASS'));

/** MySQL hostname */
define('DB_HOST', getenv('WP_DB_HOST'));
git add wp-config.php
git commit -m 'added WordPress configuration'

Add a new remote pointing at the Dokku server

git remote add dokku dokku-user@dokku:app

and push the code

git push dokku master

You will see something like this

Counting objects: 163187, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (33726/33726), done.
Writing objects: 100% (163187/163187), 84.87 MiB | 4.95 MiB/s, done.
Total 163187 (delta 128758), reused 163156 (delta 128730)
-----> Building app ...
       PHP (classic) app detected
-----> Bundling NGINX 1.4.3
-----> Bundling PHP 5.5.5
-----> Bundling extensions
       phpredis
       mongo
-----> Setting up default configuration
-----> Vendoring binaries into slug
-----> Discovering process types
       Default process types for PHP (classic) -> web
-----> Releasing app ...
-----> Deploying app ...
-----> Cleaning up ...
=====> Application deployed:
       http://app_url

To dokku@dokku:app
 * [new branch]      master -> master

app_url can appear int two formats

To finish our setup we need a couple more things:

  • create a database
  • configure the app environment with the credentials

To create a db in our app container, we'll use the MariaDB plugin for Dokku.

There's also a MySQL plugin, but it has some annoying bug and since MySQL and MariaDB
are virtually identical, we'll stick with the last one.

Installing a plugin for Dokku is as easy as running

cd /var/lib/dokku/plugins
git clone https://github.com/Kloadut/dokku-md-plugin mariadb
dokku plugins-install

Some of them don't require the final plugins-install step, but it won't hurt if you run it anyway.

Tip: you can run dokku commands on your local machine and execute them on the remote one with:
ssh dokku-host dokku-command (i.e. ssh dokku help)

We can now create the database


 ssh dokku mariadb:create app

 -----> Creating /home/dokku/app/ENV
-----> Setting config vars and restarting app
DATABASE_URL: mysql2://root:VQpzDZRrEUAkUuAI@172.17.42.1:49170/db
-----> Releasing app ...
-----> Release complete!
-----> Deploying app ...
-----> Deploy complete!

-----> app linked to mariadb/app database

-----> MariaDB container created: mariadb/app

       Host: 172.17.42.1
       Port: 49170
       User: 'root'
       Password: 'VQpzDZRrEUAkUuAI'
       Database: 'db'

and set set the Environment variables

# the format is dokku config:set app key=value key=value
# I splitted up the command on different lines for clarity
ssh dokku config:set app WP_DB_HOST='172.17.42.1:49170'
ssh dokku config:set app WP_DB_NAME='db'
ssh dokku config:set app WP_DB_USER='root'
ssh dokku config:set app WP_DB_PASS='VQpzDZRrEUAkUuAI'

If everything went right, you should now see the standard WordPress install.

Choose a title, create an admin user and you're ready to go.

You can work on your local copy, add plugins, work on your theme, and when you're happy with it, you push all the changes and the app is automatically deployed and configured.

1 Response
Add your response

28277

It doesn't work if you set multiple instances

dokku ps:scale web=2

When uploading files, you will end up with media saved in different instances.

over 1 year ago ·