Skip to content

Developing With Docker (Day 1)

TL;DR: Over this series of articles I’m going to try and build up and develop for node.js in a re-usable continer (vm) without polluting my host machine with various versions of node.js, mongodb, etc.

For a while I’ve been using vagrant and chef/puppet to develop in sandboxed environments without pulling dependency hell onto my host computer. In fact my host computers (laptop and desktop) are now pretty vanilla linux mint systems with editors and git installed. I actually version what I have on these boxes using puppet.

However, I have a few problems with vagrant for development. I don’t know if docker will solve these but we’ll see.

  • Host/Guest shared filesystems have lots of permissions issues on linux and even more on windows. The differences between usernames and root/non-root cause real issues when developing code on your host but building / generating on a VM.
  • Guest VM’s use up ram. This isn’t an issue on desktops now a days with > 24gb ram easily accessible. But it’s a big deal on laptops which are still averaging 8gb.
  • Not easy to checkpoint VMs or rebuild from a midway point. I may be missing something here with vagrant, but it’d be nice to have a good known base and restart from there.
  • Have to be online to get updates or build your box.

That said, I really like the reproduceable system/machine configurations that vagrant and chef/puppet allow you to have. I also really like being able to just checkout out a project and “vagrant up”, and have a sandboxed environment ready to go (with some caveats).

Getting Started

You should install the latest docker. Follow the instructions on the site. I’m not going to update this to keep in sync with docker (which is moving quickly).

Dockerfile

Coming from vagrant I expected some form of smart configuration file. Docker doesn’t really do that. I was also expecting redo-ability, like you get with puppet or chef. You don’t get that either. What you do get is a very simple command by command syntax which executes line by line. It’ll execute everything in the file every single time the build is run. So hopefully you’re a bashmaster.

Here’s the Dockerfile that I use to create a box with node.js installed on it:


from ubuntu:12.10

# update system and install dependencies

run apt-get update
run apt-get install -y python2.7 python build-essential wget

# get and build node

run cd /tmp && wget http://nodejs.org/dist/v0.10.15/node-v0.10.15.tar.gz
run cd /tmp && tar -xzvf /tmp/node-v0.10.15.tar.gz
run cd /tmp/node-v0.10.15 && ./configure --prefix=/usr && make && make install

So what does this do?


from ubuntu:12.10

This says start with the ubuntu:12.10 base image. This comes from the base docker boxes. For those familiar with vagrant, this is like vagrantbox.es.


run apt-get update

This runs “apt-get update” as root. In fact everything in the Dockerfile is run as root.


run apt-get install -y python2.7 python build-essential wget

This installs python 2.7 (and it’s symlinks), build-essential (make/gcc), and wget (used to pull node)


run cd /tmp && wget http://nodejs.org/dist/v0.10.15/node-v0.10.15.tar.gz

Download node into /tmp


run cd /tmp && tar -xzvf /tmp/node-v0.10.15.tar.gz

Extract node into /tmp


run cd /tmp/node-v0.10.15 && ./configure --prefix=/usr && make && make install

Build and install node.

Building The box container

Now we need to build this machine. You can clone this repository from https://github.com/gaffo/docker_nodebase, or you can just save the Dockerfile into a new directory.

To build we run:

docker build -t u1210_node .

In the directory containing the dockerfile. This will build a new container and if it succededs, it will tag it as u1210_node (so that we can use it later with a “from” directive).

. is actually the path to the directory containing the Dockerfile, so you could run this from anywhere. And containers are referenced by ID/tag not by path so context doesn’t matter at the moment. This will change when we try to share files with the container.

Using The Image

Not that we’ve built the image successfully, we can get a shell into it with

docker -i -t u1210_node /bin/bash

This will launch an interactive terminal (-i) allocating a pseudo tty (-t) with bash as the program (/bin/bash) into the container with the tag u1210_node.

Try it. You can play around all you want.

Next time I’m going to try and work up a Dockerfile iteratively with all the cruft I need to do app development with node.

13 Comments

  1. dialogue about this article here at this website, I have
    read all that, so at this time me also commenting here.|
    I am sure this paragraph has touched all the internet people, its really really pleasant piece of
    writing on building up new web site.|
    Wow, this post is pleasant, my sister is analyzing such things, so I am going to
    convey her.|
    bookmarked!!, I really like your website!|
    Way cool! Some extremely valid points! I appreciate you

    cheap authentic coach purses

    Wednesday, March 26, 2014 at 3:04 pm | Permalink
  2. mobile games wrote:

    My partner and I stumbled over here from a different web address and thought
    I might check things out. I like what I see so i am just following you.
    Look forward to looking over your web page yet again.

    Tuesday, April 15, 2014 at 7:22 am | Permalink
  3. I think this is among the most important info for me. And i am glad reading
    your article. But should remark on some general things,
    The site style is ideal, the articles is really nice : D.

    Good job, cheers

    Monday, April 21, 2014 at 10:38 am | Permalink
  4. Nice blog right here! Also your web site so much up fast!

    What host are you the usage of? Can I get your affiliate hyperlink for your host?
    I desire my website loaded up as quickly as
    yours lol

    Wednesday, April 23, 2014 at 6:39 am | Permalink
  5. You have made some decent points there. I checked on the internet for more info
    about the issue and found most individuals will go along with your views on this site.

    Thursday, May 1, 2014 at 3:24 pm | Permalink
  6. Wonderful article! This is the kind of info that should be
    shared across the web. Shame on Google for no longer positioning
    this post higher! Come on over and discuss with my web site
    . Thank you =)

    Saturday, May 17, 2014 at 9:57 am | Permalink
  7. I’m curious to find out what blog system you are using?
    I’m experiencing some small security problems with my latest website and
    I’d like to find something more risk-free. Do you have any suggestions?

    Sunday, May 18, 2014 at 2:48 am | Permalink
  8. cheap Jets jerseys china Made In usa Outlet Coupon

    Saturday, May 31, 2014 at 3:10 am | Permalink
  9. Heya i’m for the first time here. I came across this board and I find It really useful & it helped me out much.

    I hope to give something back and aid others like you helped me.

    Wednesday, June 4, 2014 at 7:55 am | Permalink
  10. cheap Saints jerseys free shipping for mens kids and womens sale

    Wednesday, June 4, 2014 at 6:51 pm | Permalink
  11. Lynwood wrote:

    Hey there! I know this is kinda off topic but I’d figured I’d ask.
    Would you be interested in exchanging links or maybe
    guest writing a blog post or vice-versa? My blog addresses a lot of the
    same topics as yours and I think we could greatly benefit from each other.
    If you are interested feel free to shoot me an e-mail.

    I look forward to hearing from you! Terrific blog
    by the way!

    Saturday, June 7, 2014 at 5:09 pm | Permalink
  12. download wrote:

    Hello it’s me, I am also visiting this website regularly, this web page is in fact pleasant and the users are genuinely
    sharing pleasant thoughts.

    Tuesday, July 8, 2014 at 5:34 pm | Permalink
  13. I do not even know how I ended up here, but I thought this post was good.
    I do not know who you are but certainly you’re going to a famous blogger if you are not
    already ;) Cheers!

    Sunday, September 21, 2014 at 3:00 am | Permalink

One Trackback/Pingback

  1. prolong gold on Monday, September 8, 2014 at 4:40 pm

    prolong gold

    confabulus › Developing With Docker (Day 1)

Post a Comment

Your email is never published nor shared.