I'm trying to get started with Docker for developing a web application with Clojure and am unsure which way to go. From what I've read so far and also looking atthe offical Docker Clojure repo, there are basically two possible ways:
- call
lein ring server(interactively or as a CMD in a Dockerfile) or - use a Dockerfile to compile your application into an uberjar and use
java -jaras theCMDon the resulting jar file.
The former seems to me to be problematic in the sense that the dev environment is not as close as possible to the production environment, given that we're probably using a:dev leiningen profile adding stuff that one would strictly not want in production (providing as few tools and "information", i.e. code on an exposed production server is always a good idea). The latter, however, seems to have the exact opposite problem: Now every change requires basically a rebuild of the image (think edit-compile-run cycle), so you would loselein rings nice re-compile on modification functionality.
How are people using this combination in practice?
PS: I'm aware that there might be some other modes of operation in practice (e.g. using Immutant or Tomcat as the deployment target or using a CI server like Hudson etc.). I'm asking about the most basic setup first here.
3 Answers3
My team and I have opted to optimize rapid feedback while developing and minimize the number of moving parts in our deploys. As a result we've opted to uselein ring server in development and opt to ship an uberjar for our deployment. I've done this with code running in docker containers and without them.
I wouldn't want to go back to using a development workflow that didn't enable seeing the results of changing code as quickly as possible. In my mind, the rapid feedback far outweighs the risk of the running services slightly differently between my local machine and production.
Also, nothing stops me from changing a couple lines of code and then starting up a local service that is running much closer to my production setup (either running a built docker image or building an uberjar locally).
Comments
There's nothing stopping you from running in production mode with Leiningen. Just use:
lein with-profile production ring serverI've used both approaches successfully, although we've settled on the uberjar approach because it gives faster startup times.
Comments
I use the second optionjava -jar ... to deploy my web application to production (not using Docker yet). This creates an edit-compile-run cycle as you said. But I don't recompile for every change. Only when I'm ready to release I create the uberjar. Of cource CI is always recommended.
Comments
Explore related questions
See similar questions with these tags.
