Playing with Dokku on Vagrant
Playing with Dokku on Vagrant
Join the DZone community and get the full member experience.Join For Free
DevOps involves integrating development, testing, deployment and release cycles into a collaborative process. Learn more about the 4 steps to an effective DevSecOps infrastructure.
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 email@example.com: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
10.0.0.2 IP address (the one that the Vagrant machine is assigned to), to the
dokku.me 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
dokku 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
vagrant reload, 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
ssh key to the Dokku server so you will be able to
git push code there.
> cat ~/.ssh/id_rsa.pub | ssh firstname.lastname@example.org "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
ssh session, and go into your folder with Node.js. I’ll be using a really simple app called
Node-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 email@example.com: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 firstname.lastname@example.org No repository field. npm WARN package.json email@example.com No readme data. npm WARN package.json firstname.lastname@example.org No repository field. ... =====> Application deployed: http://node-simple.dokku.me To email@example.com: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
NODE_ENV variable for Node.js applications. To do that, you need to create an
ENV file inside the
› ssh firstname.lastname@example.org "echo export NODE_ENV="development" > /home/git/node-simple/ENV"
Now, let’s redeploy the application, change the version in
package.json 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
http://node-simple.dokku.me, 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
http://node-simple.dokku.me. 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.