Playing with Dokku on Vagrant
Join the DZone community and get the full member experience.Join For Free
as i said previously , it’s very easy to turn a linux machine into heroku-like server. but, before setting up a paying account on amazon or digital ocean, it’s nice to just play with it locally. we will do just that by running dokku on a virtual machine. we will set up a development environment and do a local deployment first, just to see some real features.
it does not require a complex environment to run dokku locally. all you need is
preparing the environment
your box should contain a few things: git (a github account), virtualbox and vagrant. if you don’t have vagrant installed, please do so now. it makes a lot of sense to keep that kind software on your machine.
here you can find some instructions on how to do that.
you should clone a dokku repo locally. in your development folder, run:
> git clone firstname.lastname@example.org:progrium/dokku.git > cd dokku
the dokku repository already contains the vagrant file, with all required configuration data.
just for the sake of convenience, we will map the
ip address (the one that the vagrant machine is assigned to), to the
dns name, which will be handy for testing.
› sudo nano /private/etc/hosts
put the last two lines, as shown in my example:
## # host database # # localhost is used to configure the loopback interface # when the system is booting. do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost 10.0.0.2 dokku.me 10.0.0.2 node-simple.dokku.me
fire up the virtual machine
folder, you should run:
> vagrant up
it will start to prepare a new virtual environment for you:
vagrant up bringing machine 'default' up with 'virtualbox' provider... [default] setting the name of the vm... [default] clearing any previously set forwarded ports... [default] creating shared folders metadata... [default] clearing any previously set network interfaces... [default] preparing network interfaces based on configuration... [default] forwarding ports... [default] -- 22 => 2222 (adapter 1) [default] -- 80 => 8080 (adapter 1) [default] running any vm customizations... [default] booting vm... [default] waiting for vm to boot. this can take a few minutes.
i had a problem with this step a few times, so if your machine could not be booted, try to run
, which should help.
it will take about up to 20 minutes to fire up the virtual machine, install git on it, and install docker and dokku. as soon as it’s done, it’s possible to access the machine with
the last thing you need to do is upload your
key to the dokku server so you will be able to
> cat ~/.ssh/id_rsa.pub | ssh email@example.com "sudo gitreceive upload-key alexanderbeletsky"
you can use the default vagrant root password, which is "vagrant".
now, just to check that everything is fine, simply access your machine with
> vagrant ssh
then, check the version of docker:
> docker -v docker version 0.6.1, build 5105263
the instance is ready for deployment.
deploy to dokku
if you're still there, you can just quit the vagrant
session, and go into your folder with node.js. i’ll be using a really simple
, an express.js-based app that serves one html file that shows the
so, what you need to set up is a remote repository to push to:
> git remote add local-deploy firstname.lastname@example.org:node-simple
that’s all. you're ready for your first deploy, just push code to the machine with dokku:
git push local-deploy master › git push local-deploy master --force counting objects: 5, done. delta compression using up to 8 threads. compressing objects: 100% (3/3), done. writing objects: 100% (3/3), 289 bytes | 0 bytes/s, done. total 3 (delta 2), reused 0 (delta 0) -----> building node-simple ... node.js app detected -----> resolving engine versions using node.js version: 0.8.25 using npm version: 1.2.30 -----> fetching node.js binaries -----> vendoring node into slug -----> installing dependencies with npm npm warn package.json email@example.com no repository field. npm warn package.json firstname.lastname@example.org no readme data. npm warn package.json email@example.com no repository field. ... =====> application deployed: http://node-simple.dokku.me to firstname.lastname@example.org:node-simple dd05aae..ac5b6da master -> master
setting up the environment
every application requires an environment. it’s common practice to set up at least a
variable for node.js applications. to do that, you need to create an
file inside the
› ssh email@example.com "echo export node_env="development" > /home/git/node-simple/env"
now, let’s redeploy the application, change the version in
and push the code again.
› git push local-deploy master
now, the application is ready to be accessed.
accessing the application
open chrome and hit
, and you will see this response:
you can play with it a bit more by just changing some node.js end-points code and redeploying. each time, the new docker instance is started and served on
. the experience of deployment is like something you would have with heroku.
just looking at logs while the new application is deployed would give you a pretty good idea of what’s going on there.
so, your local vagrant image will be at a good starting place, before you're ready to use dokku on the cloud.
Published at DZone with permission of Alexander Beletsky, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.