Skip to main content

Vagrant up in the cloud (DigitalOcean)

It's quick and easy to start your virtual machine in the cloud if you use vagrant. Like, 55 seconds fast. I find it especially handy for toy projects that I need on the web quickly or when I don't want another virtual machine to gobble up resources on my laptop. I'm going through the steps for DigitalOcean. It's similarly easy for Amazon Web Services (AWS), but I find their web interface somewhat discombobulated.

A word on pricing: if you use the cloud for a small project it's basically free. A full day on Digital Oceans costs 16 cents. That's (hopefully) less than you tip on a cup of coffee. There are a lot of online coupons that'll get you through the first few months. AWS offers a full year for free, see

I'm assuming that you have vagrant installed and a Vagrantfile already written or generated with vagrant init. Ok, let's get started! First, download the vagrant plugin.

vagrant plugin install vagrant-digitalocean

Sign up on Digital Ocean is a cloud hosting provider. Once signed in, click on API at the top and generate a token.

Copy and paste the token. Now you have to tell vagrant who you are on Digital Ocean. Add the following to the vagrant file and delete any other line that specifies your base image, i.e., =... Replace 'YOUR TOKEN' with the token you just copied. Careful, do not push the Vagrantfile with your token to GitHub! 

  config.vm.provider :digital_ocean do |provider, override|
    override.ssh.private_key_path = '~/.ssh/id_rsa' = 'digital_ocean'
    override.vm.box_url = ""

    provider.token = 'YOUR TOKEN'
    provider.image = 'ubuntu-14-04-x64'
    provider.region = 'nyc2'
    provider.size = '512mb'
And you're ready? 55 seconds, I told you! Start your machine in the cloud by running
    vagrant up --provider digital_ocean
To find the IP of your machine, you can ssh into it and run ifconfig.
    vagrant ssh -c ifconfig

Or you can find the IP on the DigitalOcean website under Droplets. This is also the place to see which instances (Droplets) you have running and to configure them.

If you specified some kind of web service in your vagrant file, you (or anybody else) can access it under this IP. (I used a node-hello-world example). 

The only user preconfigured on the is root, not vagrant. You can delete a personal access token on the DigitalOcean website. This is very useful, if the token ended up in your git history.


Post a Comment

Popular posts from this blog

Latex: Centering table larger than textwidth

Usually, you can center tables with \center. But when the table is longer than the \textwidth, it will be align with the left side margin. You can temporarily adjust the textwidth.

% allows for temporary adjustment of side margins

And here comes a very long line. And here comes a very long line. And here comes a very long line.  \\

        \caption{This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. }

Uploading a file with JQuery

You can easily submit data in an html form via jQuery's $.post. But you need to do a little more to upload a file. I suggest the jQuery Form Plugin.

Here is the HTML form:
<html> <head> <title>Title</title> </head> <body> <form action="/test.cgi" enctype="multipart/form-data" method="post"> <input name="myFile" type="file" /> <div id="results"> </div> </form> </body> </html>
This is the Javascript file myFrom.js:
$(document).ready(function() { $('form').ajaxForm( { beforeSubmit: function() { $('#results').html('Submitting...'); }, success: function(data) { var $out = $('#results'); $out.html('Your results:'); $out.append('<div><pre>'+ data +'</pre></div>'); } …

Highlighting paragraphs in Latex

When revising a document, I often want to highlight my changes, so my collaborators can easily see what I changed.

\underline works for single words, but it puts everything in a horizontal box and long text isn't wrapped anymore.

Instead, I use the package soul and \ul to underline.
Or you can highlight text using \hl. This will underline the text unless you use the color package, then it turns into typical marker-highlight.