These are my setup scripts and notes for deploying and hosting apps on EC2 with Dokku!
- Create an EC2 instance on AWS with at least 1GB of RAM.
- The instance's security group should allow inbound connections on ports
22
,80
, and20000-65535
and outbound connections on all ports. - The instance should have an elastic IP address. This IP will be used to set up domain names. It's important that an elastic IP be used in case you decide to spin up a new instance to replace the original one.
I use the same key pair for all of my EC2 instances. Here's how I setup the connection in the ~/.ssh/config
file:
host aws-dokku
hostname aa.bb.cc.dd # <- Elastic IP Address
And then I can SSH into the instance:
ssh ubuntu@aws-dokku
- Make sure you have private/public keys configured so that you can connect to the instance via SSH.
- Run the script:
./dokku-install.sh [Public IP Address for EC2 Instance]
(all commands are run locally)
- Clone the heroku node-js-sample app:
git clone https://github.com/heroku/node-js-sample
cd node-js-sample
- Create the Dokku app:
ssh dokku@aws-dokku apps:create node-js-sample
- Add the app as a git remote:
git remote add dokku dokku@aws-dokku:node-js-sample
- Push to deploy the app:
git push dokku master
- This will launch the app on a random port on your EC2 instance. The exact URL is returned at the end of the push deployment:
=====> Application deployed:
http://aa.bb.cc.dd:25000 (nginx)
To dokku@aws-dokku:node-js-sample
* [new branch] master -> master
(all of these use node-js-sample and are executed from the local machine)
ssh dokku@aws-dokku apps:create node-js-sample
ssh dokku@aws-dokku ps:restart node-js-sample
ssh dokku@aws-dokku apps:delete node-js-sample
ssh dokku@aws-dokku config:set node-js-sample MY_ENV_VAR=foobar
- By default dokku expects your app to run on port 5000. I haven't figured out how to change this yet.
- http://dokku.viewdocs.io/dokku/deployment/dockerfiles/
In your domain configuration, set an A-record with a blank name to point at your elastic IP address, and another A-record with name www
to point at the elastic IP address.
ssh dokku@aws-dokku domains:add node-js-sample mydomain.com www.mydomain.com
ssh dokku@aws-dokku domains:remove node-js-sample mydomain.com www.mydomain.com
- shell script to spin up AWS EC2 instance.
- instructions for setting up custom docker image and run commands