To run a Clojure web app on dotCloud, you just need to build a WAR file locally and push it out.

So let’s do that. We’ll

  • Make a simple web app
  • Push out a WAR file to dotCloud
  • See it live on the web

This is very similar to the previous post Running Clojure on the AWS Beanstalk

A Hello World web app

The source is on

We’re assuming that you have lein and Java installed.

We’ll use to build the app. First the app itself.

(ns ctdean.hello
  (:use noir.core hiccup.core)
  (:require [noir.server :as server]))

;; The only page
(defpage "/" []
  "<html><body>Hello dotcloud</body></html>")

;; The handler for ring and the war file
(def handler (server/gen-handler {:mode :dev
                                  :ns 'ctdean.hello}))

And then the equally important project.clj

(defproject ctdean-dotcloud-hello "1.0.0"
  :description "hello world on dotcloud"
  :license {:name "MIT License"
            :url ""}
  :plugins [[lein-ring "0.6.2"]]
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [noir "1.2.2"]]
  :ring {:handler ctdean.hello/handler})

Let’s try it out:

% lein ring server &

You can look at it in your browser at http://localhost:3000, or on the command line:

% curl http://localhost:3000
<html><body>Hello dotcloud</body></html>

dotCloud setup

Install the tools from and setup an account.

We’ll tell dotCloud about the app and we’ll use a dir for the dotCloud app files (there are other ways, but this way is simple). We’ll also need a dotCloud config file.

Create the app

% dotcloud create hello

Make the app dir if it doesn’t exist:

% mkdir app

And make the app/dotcloud.yml config with these contents:

    type: java

Push out a WAR file

We already are using the ring plugin, so we can can use it to build the WAR file.

Build the war file with all the dependencies:

% lein ring uberwar

Put the WAR file in the app dir

% cp target/ctdean-dotcloud-hello-1.0.0-standalone.war app/ROOT.war

Push it to dotcloud:

% dotcloud push hello app

View the app

The url is printed in the log message during the push, but if you missed it the dotcloud cli can find it:

% dotcloud url hello

For me the app is running on

% curl
<html><body>Hello dotcloud</body></html>

22 Apr 2012

Previous Archive Next