Setting Up A Dokku App and Database
Buy or Subscribe
You can access this course in just a minute, and support my efforts to rid the world of crappy online courses!
Quite a few moving parts to Dokku on Digital Ocean, but, thankfully, you can do most things with some simple script commands. Once your key is setup (follow the video), you can pop in the commands below. Make sure you're logged in as root.
Creating the App and Database
Step 1: create the app.
dokku apps:create rails
This will set up a "host" for us, which is a bare Git repository with post and pre-receive hooks that will run when we push to it.
The next step is to add the PostgreSQL plugin:
The next step is to add the PostgreSQL plugin:
dokku plugin:install https://github.com/dokku/dokku-postgres.git dokku postgres:create railzdb dokku postgres:link railzdb railz
The last line there will give you your DATABASE_URL, which you need to copy for use later.
We need to work with our remote database in order to migrate our existing data, so we might want to expose the port:
We need to work with our remote database in order to migrate our existing data, so we might want to expose the port:
dokku postgres:expose railzdb
This will expose our Dockerized database on a random port. We can also specify one, if we want, by passing it as the second argument.
Adding Data
Now that we have our connection information, we can send our tables and data up to our Dokku database. The command is, thankfully, very simple, but you do need to have Postgres installed locally. If you don't, you can also use migrations and seeds, which we'll discuss later on.
psql $DATABASE_URL < ./db/db.sql