Skip to content

Instantly share code, notes, and snippets.

@MarcDiethelm
Last active December 3, 2018 18:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcDiethelm/7622406 to your computer and use it in GitHub Desktop.
Save MarcDiethelm/7622406 to your computer and use it in GitHub Desktop.

How to deploy Heroku-style on Digital Ocean with Dokku

Because a basic VPS at Digital Ocean costs $5 a month. And you can host as many apps as you want. An nginx serves as a proxy for your apps.


Update

Now you don't have to install Dokku yourself anymore. There's a pre-configured Dokku image available on Digital Ocean, that you can spin up with just a few clicks...

VM

  • Create a fresh Ubuntu 13.04 x64 VM. Use the desired domain as hostname example.com.

  • Set up the domain to point to the new VM's IP.

  • Set up a ~/.ssh/config for the key you want to use on the server.

     Host <host alias>
     	User dokku
     	Hostname example.com
     	PreferredAuthentications publickey,password
     	IdentityFile /Users/<your username>/.ssh/id_rsa
     	RequestTTY yes
    

    Now you don't have to type the user and full domain when pushing or specify which key to use (if you have multiple) in later ssh and git commands.

    You can't use RequestTTY in OpenSSH versions older than 5.8. (e.g. On MacOS < 10.9). You should instead execute ssh with the -t option.

  • Upload your public key for easy installation from the cloud.

    curl -s ssh.keychain.io/<your email>/<key identifier>/upload | bash

  • SSH into the VM.

    ssh root@<host alias> And enter the root pw.

    • Install your key.

      curl -s ssh.keychain.io/<your email>/<key identifier>/install | bash

    • Install Dokku.

      wget -qO- https://raw.github.com/progrium/dokku/v0.2.1/bootstrap.sh | sudo DOKKU_TAG=v0.2.1 bash

    • This also creates a user called dokku.
      Use su - dokku when logged in as root to drop down to normal privileges.

    • Make sure your domain is in /home/dokku/VHOST. Remove localhost entry if present.

    • Exit.

  • Set up the command to be executed when 'dokku' user connects with ssh (e.g.while pushing to the server.)

    cat ~/.ssh/id_rsa.pub | ssh root@<host alias> "sudo sshcommand acl-add dokku <your username>"

    (username is not being used so far.)


Apps

  • Add the remote to your working copy.

    git remote add <remote name> <host alias>:app

    When pushing this will result in an app at app.example.com. You can force an different subdomain with git remote add deploy <host alias>:app.example.com (or none).

  • Deploy.

    git push <remote name> master

    Your app is uploaded and installed.
    To push a specific branch use git push <remote name> <branch name>:master

  • Control dokku

    You can execute dokku commands from your local shell.

    ssh <host alias> help

    Just replace help with the dokku command, e.g. to set environment variables:

    ssh <host alias> config:set <app> KEY1=VALUE1 [KEY2=VALUE2 …]

    The app is restarted with the new settings.
    The variables are stored in /home/dokku/xtc/ENV.

    You should execute ssh with the -t option if you don't have RequestTTY yes in your ssh config.


Sources

@josegonzalez
Copy link

That wiki link hasn't existed in ages (if ever).

See here for our nginx docs.

@josegonzalez
Copy link

Also this references an old version of dokku. Like several years old. We have more complete docs here and here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment