Installing Dokku to Vultr


Dokku“ is a private PaaS OSS application like Heroku.
Vultr“ is a Cloud Hosting service especially VPS.

This article desribe installation “Dokku“ to “Vultr“.


🍮 Setup Server on Vultr

  1. Select “create New Server(e.g. 123.123.123.123)”, select “Ubuntu 14.04 LTS”
  2. Once your server has been created, wait for installation to complete.
  3. SSH into your Server as root and run the following commands:
# login server by SSH
ssh root@dokku.me

# Updating apt-get
apt-get update
apt-get -qq upgrade

# Installing linux-image-virtual & linux-image-extra-virtual & language-pack-ja
apt-get install -y git make linux-image-virtual linux-image-extra-virtual language-pack-ja dos2unix

# Set Timezone for Server
mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
service cron restart

🐡 Setup swap space

# login server by SSH
ssh root@dokku.me

cat /proc/swaps
# Filename Type Size Used Priority

# create a folder for swap
mkdir /var/swap

# create 2GB swap file
dd if=/dev/zero of=/var/swap/swap0 bs=1M count=2048

# Set permission
chmod 600 /var/swap/swap0

# Setup swap configuration
mkswap /var/swap/swap0
swapon /var/swap/swap0
echo '/var/swap/swap0 swap swap defaults 0 0' >> /etc/fstab

cat /proc/swaps
# Filename Type Size Used Priority
# /var/swap/swap0 file 2097148 211176 -1

😼 Installation for Dokku

# login server by SSH
ssh root@dokku.me

# Installing Dokku
cd /tmp
wget https://raw.githubusercontent.com/dokku/dokku/v0.7.2/bootstrap.sh
DOKKU_TAG=v0.7.2 bash bootstrap.sh

🚕 Submit public SSH key & domain to dokku web page

Open dokku.me or 123.123.123.123 by your web browser and submit public SSH key & domain name.

🚌 Install Postgress on Dokku

# login server by SSH
ssh root@dokku.me

# Install PostgreSQL plugin on dokku
dokku plugin:install https://github.com/dokku/dokku-postgres.git

# Create instance of PostgreSQL
dokku postgres:create dokku_sample_db

# Create instance of Application
dokku apps:create dokku_sample_app

# Relate PostgreSQL instance with the application
dokku postgres:link dokku_sample_db dokku_sample_app

🗻 Setup DNS

Setup domanin & IP to your DNS

dokku.me   A 123.123.123.123
*.dokku.me A 123.123.123.123

🗽 Set domain & IP to your hosts

Add your domain & IP to local /etc/hosts:

123.123.123.123 dokku.me

🎉 Set SSH Configuration

Add SSH Configuration to local ~/.ssh/config:

Host dokku.me
HostName 123.123.123.123
IdentityFile ~/.ssh/id_rsa.dokku.me
User root

🐯 Deploy your app

# From your local machine
git clone git@github.com:heroku/ruby-rails-sample.git

# Each official datastore offers a `link` method to link a service to any application
git remote add dokku dokku@dokku.me:ruby-rails-sample

# Installing dokku command line tool
gem install dokku-cli

# Set secret key for Rails
bundle exec rake secret
dokku config:set SECRET_KEY_BASE="上で生成された文字列"
dokku config:set CURL_TIMEOUT=1200

# Deploy
git push origin master

# Show app by browser
dokku open

👽 dokku-cli Cheat Sheat

# Basic Commands
dokku run # Run a one-off command in the environment of the app
dokku ssh # Start an SSH session as root user
dokku logs [-t] # Display logs for the app (-t follows)
dokku help [COMMAND] # Describe available commands or one specific command

# Configuration Commands
dokku config # Display the app's environment variables
dokku config:get KEY # Display an environment variable value
dokku config:set KEY1=VALUE1 [KEY2=VALUE2 ...] # Set one or more environment variables
dokku config:set:file # Set one or more environment variables from file
dokku config:unset KEY1 [KEY2 ...] # Unset one or more environment variables

# Process / Container Commands
dokku ps # List processes running in app container(s)
dokku ps:rebuild # Rebuild the app
dokku ps:restart # Restart the app container
dokku ps:start # Start the app container

# その他便利コマンド
dokku nginx:build # (Re)builds nginx config for the app
dokku open # Open the app in your default browser
dokku url # Show the first URL for the app
dokku urls # Show all URLs for the app

🐮 Dokku app at the root domain of the dokku server

# login server by SSH
ssh root@dokku.me

dokku domains:add myapp mydomain.com

😎 Special Thanks

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!