Build your own PaaS with Dokku
Posted on August 25, 2018 (Last modified on October 23, 2024) • 4 min read • 820 wordsI was looking for some “play” deployment method for a couple of things I want to try out. Most of them require a database. And it should be cheap, cause I don’t have any load on them and don’t earn any money, so I don’t want to spend basically no money if possible. The usual suspects are too expensive - AWS, Heroku, etc.
So I looked around and found Dokku.
Dokku is a set of - hang on - shell scripts - which basically emulate Heroku on a machine of your own. It’s integrated with Digital Ocean droplets out of the box, if you want it. And the whole thing is 5 € / month, which is perfect. It also integrates with a Dockerfile based deployment, so you do git push and everything just works.
It’s amazing.
This is how you get started. But before you can get started, you need a domain you control, either on AWS or any other hoster. This is for routing traffic to your deployments later. You also need a public SSH key, or better a public / private key pair. Once you have both you can …
While the droplet is being created, you can also create a project locally to test it later:
$ mkdir dokku-test
$ cd dokku-test
$ git init
$ echo "FROM tutum/hello-world" > Dockerfile
$ git add Dockerfile
$ git commit -m "Initial commit"
In this little test project we only create a Dockerfile from an hello-world image which displays “Hello world” in a browser so we can verify it worked.
Once the droplet is done, you can start setting up your personal little PaaS. First, you have to configure your DNS. We will set up a wildcard entry for our deployments, and a non-wildcard entry for git. Let’s assume your domain is for-myself.com
, then you would add …
my-paas.for-myself.com
, type “A” (or “AAAA” if you are IPv6) to your droplet IP*.my-paas.for-myself.com
just the sameThen you SSH into your droplet, and create your dokku project. (This is something you have to do for every project). All you have to do for this is:
$ ssh root@DROPLET_IP
~# dokku apps:create hello-world
-----> Creating hello-world... done
~# _
Done.
Now you configure a git remote URL for your project, and push it:
$ git remote add dokku dokku@my-paas.for-myself.com:hello-world
Again - done. If you push your project now (assuming DNS is already set), everything should happen automagically:
$ git push --set-upstream dokku master
X11 forwarding request failed
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 241 bytes | 241.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
-----> Cleaning up...
-----> Building hello-world from dockerfile...
remote: build context to Docker daemon 2.048kB
Step 1/1 : FROM tutum/hello-world
latest: Pulling from tutum/hello-world
658bc4dc7069: Pulling fs layer
[... TRUNCATED ...]
983d35417974: Pull complete
Digest: sha256:0d57def8055178aafb4c7669cbc25ec17f0acdab97cc587f30150802da8f8d85
Status: Downloaded newer image for tutum/hello-world:latest
---> 31e17b0746e4
Successfully built 31e17b0746e4
Successfully tagged dokku/hello-world:latest
-----> Setting config vars
DOKKU_DOCKERFILE_PORTS: 80/tcp
-----> Releasing hello-world (dokku/hello-world:latest)...
-----> Deploying hello-world (dokku/hello-world:latest)...
-----> Attempting to run scripts.dokku.predeploy from app.json (if defined)
-----> No Procfile found in app image
-----> DOKKU_SCALE file not found in app image. Generating one based on Procfile...
-----> New DOKKU_SCALE file generated
=====> web=1
-----> Attempting pre-flight checks
For more efficient zero downtime deployments, create a file CHECKS.
See http://dokku.viewdocs.io/dokku/deployment/zero-downtime-deploys/ for examples
CHECKS file not found in container: Running simple container check...
-----> Waiting for 10 seconds ...
-----> Default container check successful!
-----> Running post-deploy
-----> Creating new /home/dokku/hello-world/VHOST...
-----> Setting config vars
DOKKU_PROXY_PORT_MAP: http:80:80
-----> Configuring hello-world.my-paas.for-myself.com...(using built-in template)
-----> Creating http nginx.conf
-----> Running nginx-pre-reload
Reloading nginx
-----> Setting config vars
DOKKU_APP_RESTORE: 1
=====> Renaming container (14c349cb496d) amazing_snyder to hello-world.web.1
-----> Attempting to run scripts.dokku.postdeploy from app.json (if defined)
=====> Application deployed:
http://hello-world.my-paas.for-myself.com
To my-paas.for-myself.com:hello-world
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'dokku'.
And if you open your URL now (which is hello-world.my-paas.for-myself.com
) you should see this image:
Now, for 5 € / month you get:
That’s absolutely incredible. Oh, and did I mention that the maintainers are not only friendly, but also super responsive and incredibly helpful on Slack?