Deploy your clojure app with docker
You’ve built an app in clojure and you’d like to share it with the world (or at least show it to someone)? Then one of the easiest ways to do it, is with the help of docker.
I assume that you use leiningen for your project. If not you’ll need to adapt your Dockerfile a bit, but you should get an idea how it works.
Inside the root directory of your project, create the following file with the name “Dockerfile”:
So what does this file do? It will first use the clojure image as base container, then it will retrieve all dependencies and finally it will build an uberjar (a jar containing all dependencies of your project.
A few things to note here:
- if you have specified a name for your uberjar in your project, you must adapat the step where the *.standalone.jar is renamed to app-standalone as it wouldn’t work otherwise.
For example, if you have the following in your project.clj:
Then you will need to adapt your Dockerfile to:
The next step depends on where you want to deploy your docker app. If you want to deploy it on your own Linux machine, just install Docker with the package manager of your distribution and run inside your project directory:
On your local Windows or Mac machine, you can do something aquivalent with Docker for Windows or Docker for Mac.
If you want to share your app with someone, I can recommend you to create a droplet on Digital Ocean. There you can setup a virtual machine with Docker installed in a few minutes which will cost you a few cents per hour (you even get $100 free credit when you register the first time). It’s great when you want to deploy your app or if you want to try new technologies like e.g. databases without needing to install them on your machine.