Skip to content

Instantly share code, notes, and snippets.

@tinhnq
Forked from shirren/vultr_dokku_rails.md
Created November 11, 2017 04:21
Show Gist options
  • Save tinhnq/39743562620e6a2f7dcd14b7f61dfcb5 to your computer and use it in GitHub Desktop.
Save tinhnq/39743562620e6a2f7dcd14b7f61dfcb5 to your computer and use it in GitHub Desktop.
How to deploy a Rails 4/5 app on Vultr or Digital Ocean using a stock Ubuntu image with Dokku 0.6.5v

Rails/Dokku Deployment Procedure

This procedure has been tested on Vultr, and Digital Ocean. In theory it should work on any VPS as long as the linux instance is Ubuntu. There might be some subtle differences for other linux variants.

  1. Create a new compute instance on Vultr using an 64-bit ubuntu image
  • From the available compute instance sizes, pick at a minimum a server with 1024Mb of memory. Compute instances with smaller sizes will fail on deploy
  1. ssh on to the server root@ipaddress
  • If this is your first deploy onto Vultr ensure you've created a ssh key pair firstly. Then add your public key during the compute instance creation procedure
  • Now wait for Vultr to provision an instance of your new image
  1. Install Dokku 0.6.5
  1. Test the dokku install
  • dokku --help
  • dokku apps
  1. Add dokku to the docker group
  • sudo usermod -aG docker dokku
  1. Create an A record in your dns provider to point to the newly assigned VM's ip address
  2. On the VM create and app
  • dokku apps:create app_name
  1. On the VM create the postgres database
  1. Link the service to the app (by convention our app name and db name will be the same)
  • dokku postgres:link db_name app_name
  • This will create a config var named DATABASE_URL
  1. Add any environment variables to the new VM
  • dokku config:set storm VAR=VALUE
  1. Deploy the app (On your dev machine)
  • git remote add env dokku@host_name:app_name
  • git push env master
  1. Remap the nginx port mapping for the server
  • dokku config:set app_name DOKKU_PROXY_PORT_MAP=http:80:3000
  1. Run any rails commands to set the app up
  • dokku run app_name rake db:migrate
  1. Scale any present workers
  • dokku ps:scale app_name web=1 worker=1
  1. To expose the postgres database
  • dokku postgres:expose app_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment