Dokku is a mini-Heroku just for you. Run you rown PaaS.
In this set of notes we deploy a demo Ruby on Rails app that uses PostgreSQL, Redis, Memcached and Let's Encrypt. You can see it at suggestotron.apps.tulsarb.org.
Use referral link for $10 credit.
Create a Droplet:
-
One-click apps:
Dokku 0.11.3 on 16.04
-
Size: 2 GB / 1 vCPU for $10 a month
- Size shouldn't matter to get started
- Since base $5 droplets are now 1GB
-
Datacenter: Typically closest to your customer base.
-
Additional options: Monitoring
- It pre-installs the agent, can do later too.
-
Upload SSH Key:
cat ~/.ssh/id_ras | pbcopy
-
Name: tulsarb - doesn't matter too much.
Firewalls are under Networking in the dashboard:
- Name: doesn't matter, web-app-firewall
- Inbound Rules: Turn on SSH, HTTP and HTTPS.
- Outbound Rules: Default are okay.
- Remove IPv6: Dokku no like.
- Apply to Droplets, search for tulsarb.
Optional but makes it easier to work with!
A record of apps.tulsarb.org
to the IP address.
CNAME record of *.apps.tulsa.org
to apps.tulsarb.org
.
This let's all of our apps automatically get a hostname of <app-name>.apps.tulsarb.org
apt update # fetch the updates
apt upgrade # apply the updates
Initial Setup via the Web:
-
Visit the IP address via HTTPS
-
SSH key should be pre-filled
-
Set the hostname to:
apps.tulsarb.org
-
Enable virtual host naming for pretty URL's like:
https://<app-name>.apps.tulsarb.org
Continue Setup via SSH:
SSH into the server via: ssh [email protected]
Install Plugins:
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
sudo dokku plugin:install https://github.com/dokku/dokku-redis.git
sudo dokku plugin:install https://github.com/dokku/dokku-memcached.git
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
Configure Global E-mail Address for all SSL Certificates
dokku config:set --global [email protected]
Have your application ready to deploy!
Create the application in Dokku:
dokku apps:create suggestotron
Create Services and Link them to Your App:
A service is a Docker container running the specific service such as PostgreSQL or Redis. A link is connecting your application to that service. It let's them communicate plus sets ENV variables for your application to use for communication. There is some work to allow re-using one database service for multiple apps but right now think of it as a new service per application.
# Databases
dokku postgres:create suggestotron-db
dokku postgres:link suggestotrone-db suggestotron # sets DATABASE_URL ENV for you
# Redis
dokku redis:create suggestotron-redis
dokku redis:link suggestotron-redis suggestotron # sets REDIS_URL ENV for you
# Memcached
dokku memcached:create suggestotron-memcached
dokku memcached:link suggestotron-memcached suggestotron # sets MEMCACHED_URL ENV for you
Set any other needed environmental variables:
dokku config:set suggestotron AWS_ACCESS_KEY_ID=thekey
dokku config:set suggestotron AWS_REGION=us-east-1
dokku config:set suggestotron MAILER_HOST=smtp.server.com
# etc...
Configure git remotes:
git remote add dokku [email protected]:suggestotron
Deploy:
This deploy process looks like Heroku because it detects your app type and uses the appropirate open-soruced Heroku build pack. It uses the Procfile
to know how to start processes.
git push dokku master
Setup SSL certificates:
Do this after initial deploy and any domain adds and removes.
dokku letsencrypt suggestotron
Start the Worker Process too:
dokku ps:scale suggestotron web=1 worker=1
One Off Commands:
Things like Rails database migrations or rake tasks:
dokku run suggestotron rake db:migrate
Deploy Hooks:
You can do things like run migrations automatically. Read more.
Tweak Dokku default scale size:
Dokku only starts one web worker by default, if you don't want to run the scale command (once) you can set the default to start a worker by creaking a DOKKU_SCALE
file in your apps root directory:
# /DOKKU_SCALE
web=1
worker=1
Test your app and fix issues:
dokku logs suggestotron -t # tail all logs
dokku logs suggestotron -p web # tail just web process
dokku logs suggestotron -p worker # tail just worker process
Backround worker doesn't auto-restart:
After deploying I noticed the background worker wasnt' restarting. You can restart the whole app with:
dokku ps:restart suggestotron
Run recurring jobs and tasks:
Dokku supports cron for scheduling recurring tasks and jobs. Just read through the documentation for configuration help.
Run dokku
commands locally:
Now you don't need to type the app name each time. The dokku
command looks for the Git remote and extrapolates the app name. Plus you don't have to be ssh'd into the server for most things. There are many different packages for this client.
gem install dokku-cli