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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# login server by SSH
ssh [email protected]
# 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# login server by SSH
ssh [email protected]
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

1
2
3
4
5
6
7
# login server by SSH
ssh [email protected]
# 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# login server by SSH
ssh [email protected]
# 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

1
2
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:

1
123.123.123.123 dokku.me

Set SSH Configuration

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

1
2
3
4
Host dokku.me
HostName 123.123.123.123
IdentityFile ~/.ssh/id_rsa.dokku.me
User root

Deploy your app

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# From your local machine
git clone [email protected]:heroku/ruby-rails-sample.git
# Each official datastore offers a `link` method to link a service to any application
git remote add dokku [email protected]: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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Basic Commands
dokku run <cmd> # 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 <path/to/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

1
2
3
4
# login server by SSH
ssh [email protected]
dokku domains:add myapp mydomain.com

Special Thanks