The Hack programming language is the new hotness. Now that Facebook uses it for basically everything, every new startup is wondering if they should start using it too. But how do you even get started?
What if I told you that you could be running a Hack server on your laptop in 30 seconds with Docker?
(Edit: Docker Machine, part of the Docker Toolset, is recommended over boot2docker)
$ brew install boot2docker # if you are on OS X $ boot2docker init # if you are on OS X $ boot2docker up # if you are on OS X $ sudo gem install building $ mkdir hackapp $ cd hackapp $ echo '<?hh echo "Hello World"; %>' > index.hh $ building -b https://github.com/CenturyLinkLabs/heroku-buildpack-hhvm.git -f ctlc/buildstep:ubuntu12.04 hhvm-app create Dockerfile building docker build -t hhvm-app:latest . hint To run your app, try: docker run -d -p 8080 -e "PORT=8080" hhvm-app hint To re-build your app, try: docker build -t hhvm-app . $ HHVM_APP_ID=$(**docker run -d -p 8080 -e "PORT=8080" hhvm-app**) $ curl `docker port $HHVM_APP_ID 8080` Hello world
If your app gets more complex than "Hello World", you will need to create an updated container. To do this, you can use the built-in
docker build command because the building gem created a Dockerfile for you. This will take you a fraction of the time that the initial build took because Docker caches your images in stages and most of your image will not have changed at all.
$ echo '<?hh echo "Something more complex"; %>' > index.hh $ docker build -t hhvm-app . $ docker stop $ HHVM_APP_ID $ HHVM_APP_ID=$(docker run -d -p 8080 -e "PORT=8080" hhvm-app) $ curl `docker port $HHVM_APP_ID 8080` Something more complex
This is just a simple example of how much better the developer tooling around Docker has become over the last year. With Docker 1.0 just around the corner, there has never been a better time to start incorporating it into your daily workflow. If you are ready to get your feet wet with CoreOS, try our Building Your First App on CoreOS tutorial.