Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing Dokku and Deploying a Django App

Deploying Django on Dokku

This Gist: http://is.gd/dokkudjango

DigitalOcean: https://www.digitalocean.com/

Dokku: https://github.com/progrium/dokku

Dokku-Postgres: https://github.com/Kloadut/dokku-pg-plugin

Deploy a Droplet on DigitalOcean

Add an SSH key to DigitalOcean before hand to make SSHing into you new box easier and more secure.

  1. Click "Create"
  2. Enter hostname, select size and region
  3. Select Ubuntu 13.04 x64 as the Image
  4. Select your SSH key
  5. Click "Create Droplet"

Setup DNS

  1. Add a blank A Record pointing to the IP Address of your new Droplet
  2. Add a wildcard (*) A Record pointing to the same domain to capture all of the subdomains.

Install Dokku

  1. SSH into your Droplet. Just ssh root@yourdomain.com should work if you add an SSH Key. If not, DigitalOcean emailed you a root password.
  2. Copy and Paste and oneline installer from the Dokku Repo README. Something like this wget -qO- https://raw.github.com/progrium/dokku/master/bootstrap.sh | sudo bash
  3. Wait 5 minutes.
  4. Associate an SSH key with a git user as the installer instruct you to. Something like this cat ~/.ssh/id_rsa.pub | ssh root@yourdomain.com "gitreceive upload-key alex"
  5. Add domain to VHOST
cd /home/git
echo yourdomain.com >> VHOST

Install Dokku Postgres Plugin

Install the Postres Plugin. From inside your Droplet:

cd /var/lib/dokku/plugins
git clone https://github.com/Kloadut/dokku-pg-plugin
dokku plugins-install

Create a new container which contains Postgres. We are going to deploy our Django app to this container in the future.

dokku postgresql:create myapp

Deploy a Django App

Dokku uses Heroku's BuildPack system for deploying applications. Refer to Heroku's Django Docs to figure out how to prepare your app for deployment. This is mainly concerned with Database connection configuration, WSGI configuration and static file serving.

I made a quick Django base project based on Heroku's documentation. You can get it here

Add a new git remote to your project pointed at your new Postgres container on your Dokku instance then push to it.

git remote add dokku git@yourdomain.com:myapp
git push dokku master

OMG! You can now visit your app!

Running manage.py commands

This is the only hacky part of the process. From inside your Droplet, lets a terminal session inside our container

docker images # See a listing of all of your docker images
docker run -i -t app/myapp /bin/bash # Start an interactive terminal inside of your container

Now we need to bootstrap our terminal session with all of the correct paths and environment variables.

export HOME=/app
for file in /app/.profile.d/*; do source $file; done
hash -r
cd /app # This is the folder where django app got deployed

Now you can run your manage.py commands

python manage.py syncdb
@alextucker
Copy link
Author

alextucker commented Aug 21, 2013

I just want to thank everyone for coming out tonight! Enjoy the 🍺 and 🍕
If you have any questions you can contact me at alex at bnotions.com
Also check out our new profile on CoderWall https://coderwall.com/team/bnotions

@adamtwiss
Copy link

adamtwiss commented Jan 23, 2014

Thanks for a nice tutorial. Note though that your sample app has a blank databases string, so your syncdb etc fail.
Also that the git user doesn't exist, it's a dokku user now.

@andybak
Copy link

andybak commented Mar 7, 2014

There's now a premade 'dokku' application available when you create a new droplet.

I'd love to see these instructions updated to use that. I figured I could skip 'Install Dokku' and just straight to 'Install Dokku Postgres Plugin' but it wasn't that simple. Git doesn't seem to be installed and I don't know whether to use git@, root@ or something else entirely when I add the git remote.

@jameskeane
Copy link

jameskeane commented May 18, 2014

For running manage.py commands you can also use dokku run <app> bash which will drop you into a bash session with the right environment set up.

@samgclarke
Copy link

samgclarke commented Sep 11, 2015

dokku run <app> bash is a really useful command! Thanks!

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