Installation & Configuration Guide - Dokku DigitalOcean
- Connect to our droplet via SSH
- Add Swap on Ubuntu 14.04
- Installing Dokku Plugins
- Creating Apps
- Domains Configuration
- Configuring Dokku Plugins
Connect to our droplet via SSH
Log in to your droplet via ssh:
ssh root@your-droplet-ip -p 22
Make sure the Dokku user can connect using your SSH key as well
cat /root/.ssh/authorized_keys | sshcommand acl-add dokku dokku
Add Swap on Ubuntu 14.04
Add a 2GB swap file:
sudo dd if=/dev/zero of=/swapfile bs=512M count=4
Make the Swap File Permanent
sudo nano /etc/fstab
At the bottom of the file, you need to add a line that will tell the operating system to automatically use the file you created:
/swapfile none swap sw 0 0
Tweak your Swap Settings
sudo sysctl vm.swappiness=10
sudo sysctl vm.vfs_cache_pressure=50
This setting will persist until the next reboot
sudo nano /etc/sysctl.conf
At the bottom, you can add:
vm.swappiness=10
vm.vfs_cache_pressure=50
Installing Dokku Plugins (Database, Services...)
Run this commands to install your desire Dokku Plugins, you can check the Plugins list here
To install official Postgres Dokku Plugin:
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
To install official ElasticSearch Dokku Plugin:
sudo dokku plugin:install https://github.com/dokku/dokku-elasticsearch.git elasticsearch
To install official MySQL Dokku Plugin:
sudo dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql
Creating Dokku Apps
To create Apps:
dokku apps:create staging
dokku apps:create production
Apps Details Commands:
apps # List your apps
apps:create <app> # Create a new app
apps:destroy <app> # Permanently destroy an app
apps:rename <old-app> <new-app> # Rename an app
Domain Configuration
To add domains to an app:
dokku domains:add <app> <domain>
Domains Details Commands:
domains:add <app> <domain> [<domain> ...] # Add domains to app
domains:add-global <domain> [<domain> ...] # Add global domain names
domains [<app>] # List domains
domains:clear <app> # Clear all domains for app
domains:disable <app> # Disable VHOST support
domains:enable <app> # Enable VHOST support
domains:remove <app> <domain> [<domain> ...] # Remove domains from app
domains:remove-global <domain> [<domain> ...] # Remove global domain names
Configuring Dokku Plugins
Database Advanced Configuration (MySQL, Postgres, Mongo...)
First Steps for configuring any Database to your app (Example MySQL): Creating a container with MySQL Dokku Plugin:
dokku mysql:create <name>
Note: if you want to install a specific version, use this followings commands before creating your database container, as example here we are using MySQL:
export MYSQL_IMAGE="mysql" export MYSQL_IMAGE_VERSION="5.5"
For Deployment purpose you can Change database adapter
Note: It's possible to change the protocol for DATABASE_URL by setting the environment variable MYSQL_DATABASE_SCHEME on the app:
dokku config:set <app> MYSQL_DATABASE_SCHEME=mysql2
CAUTION: this will cause DATABASE_URL to be set as mysql2://mysql:SOME_PASSWORD@dokku-mysql-:3306/
CAUTION: Changing MYSQL_DATABASE_SCHEME after linking will cause dokku to believe the service is not linked when attempting to use dokku mysql:unlink or dokku mysql:promote
Use this command to Link a MySQL container or DB to an existing app:
dokku mysql:link <name> <app-name>
Expose service to custom port number, this allow you to remote connect using a 3rd party DBMS like MySQL-Workbench, pgAdmin...
dokku mysql:expose <servicename> <port>
example--> dokku mysql:expose <stagingdb> <3307>
Use this command to connect via mysql terminal to a mysql container :
dokku mysql:connect <name>
Use this command to show all your mysql containers
dokku mysql:list
Use this command to show all your mysql containers
dokku mysql:list
Get Root Password for MySQL on Dokku
The Root user and its Password should be located in /var/lib/dokku/services/mysql/your-service/ROOTPASSWORD
cat /var/lib/dokku/services/mysql/your-service/ROOTPASSWORD
Creating a service on ElasticSearch Plugin:
dokku elasticsearch:create <name>
Link service to an app:
dokku elasticsearch:link <name> <app>
Persistent storage for your Rails apps with Dokku and Docker
First create a storage directory on the host server:
mkdir -p /storage/<appname>/<environment>/public/uploads
Then tell Dokku where to save your images uploads:
dokku docker-options:add appname run,deploy -v "/storage/<appname>/<environment>/public/uploads:/app/public/uploads"
Extra (Optional): Troubleshooting > Deployment fails because of slow internet connection
Change this values to fix this issue:
dokku config:set --global CURL_TIMEOUT=600
dokku config:set --global CURL_CONNECT_TIMEOUT=30
[dokku_mysql]: <https://github.com/dokku/dokku-mysql