-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathindex.html
More file actions
501 lines (340 loc) · 23.1 KB
/
index.html
File metadata and controls
501 lines (340 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Run clojure projects on Docker with lein-uberimage - Pallet</title>
<link rel="stylesheet" href="http://67516654d2ef99c3042d-b9d92f522aee852c07f26ce9d1459c9c.r8.cf1.rackcdn.com/20140625-01/css/bootstrap.min.css">
<link rel="stylesheet" href="http://67516654d2ef99c3042d-b9d92f522aee852c07f26ce9d1459c9c.r8.cf1.rackcdn.com/20140625-01/css/pallet.css">
<link rel="stylesheet" href="http://67516654d2ef99c3042d-b9d92f522aee852c07f26ce9d1459c9c.r8.cf1.rackcdn.com/20140625-01/css/social-buttons-3.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">
<link rel="stylesheet" href="http://67516654d2ef99c3042d-b9d92f522aee852c07f26ce9d1459c9c.r8.cf1.rackcdn.com/20140625-01/css/css.css">
<link rel="stylesheet" href="http://67516654d2ef99c3042d-b9d92f522aee852c07f26ce9d1459c9c.r8.cf1.rackcdn.com/20140625-01/css/highlight.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Pallet is a platform for agile and programmatic automation of infrastructure in the cloud, on server racks or directly on virtual machines." />
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#topbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">PalletOps</a>
</div> <!-- /.navbar-header -->
<div class="collapse navbar-collapse" id="topbar-collapse">
<ul class="nav navbar-nav">
<li class=" " >
<a href="/pallet/doc">
Documentation
</a>
</li>
<li class="active " >
<a href="/blog">
Blog
</a>
</li>
<li class=" " >
<a href="/services">
Services
</a>
</li>
<li class=" hidden-sm hidden-xm" >
<a href="/support">
Support
</a>
</li>
<li class=" hidden-sm hidden-xm" >
<a href="/contact">
Contact
</a>
</li>
<li class=" hidden-sm hidden-xs" >
<a href="https://github.com/pallet/pallet">
<i class="fa fa-github"></i> Code
</a>
</li>
</ul>
<form class="navbar-form navbar-right" role="search"
method="get" action="http://www.google.com/search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search"
name="q" maxlength="255">
<input name="sitesearch" type="hidden" value="palletops.com">
</div> <!-- /.form-group -->
</form>
</div> <!-- /#topbar-collapse -->
</div> <!-- /.container -->
</nav>
<div class="post">
<div class="container">
<div class="row">
<div class="col-md-9 content">
<div class="page-header">
<h1 class="title"><a href="">Run clojure projects on Docker with lein-uberimage</a></h1>
</div>
<div class="post-content">
<p>We built a lein plugin to make it easy to run clojure projects in Docker containers. This article first introduces containers and Docker, and then shows how you can effortlessly create such containers for your Clojure projects with <code>lein uberimage</code>. </p>
<p><image src="/images/docker-large-h-trans.png" alt="Docker logo" class="img-responsive"></p>
<h2>Why Containers and Why Docker</h2>
<p>A container is a lighweight form of computer virtualization. Containers run within a host, and a host can run many containers concurrently. Each container is functionally equivalent to a computer loaded with a full OS, but behind the scenes all containers in the same host are sharing the same host resources: kernel, memory, IO, and disk.</p>
<p>There are many ways of virtualization technologies used today, VirtualBox, Xen (used by Amazon Web Services) and vmware to name a few, but what makes containers special is their lightweight nature. Each container uses very little resources (disk, memory, cpu) and they all boot orders of magnitude faster than a virtual machine or
a computer.</p>
<p>Containers are very convenient for both development and production environments. For development, they provide a fast and simple way to run different and isolated runtime environments for each application. In production, they are very fast and efficient, with the added bonus that containers in production always match the ones in development; the same exact containers are used during all app's lifecycle.</p>
<p><a href="http://www.docker.com">Docker</a> is a novel container technology for Linux that provides a very low friction access to containers. Containers have been around for a while, and the Linux kernel has provided key container technologies for a while already. Docker wraps all these kernel features under a high level API and defines a standard container and image formats using union filesystems. To make containers easy to share and distribute, Docker also provides public and private image repositories. All these features have brought containers to the masses.</p>
<p>Although Docker is currently Linux only, you can use it on OSX installing <a href="http://boot2docker.io">boot2docker</a></p>
<p>For a more detailed introduction to Docker, check out this video on <a href="http://sysadmincasts.com/episodes/31-introduction-to-docker">sysadmincasts.com</a>.</p>
<h2>Docker images</h2>
<p>Each container is a process tree that is started from an existing image. These images contain a filesystem with the files necessary to run your application. Sometimes this entails a linux distribution and sometimes just one statically linked binary. The common practice in the Docker world is to build a custom image for each type of service you intend to run. This contrasts with other forms of virtualization where you start the VMs from a base image and then you configure them with the required software. In the case of VMs, the time it takes a VM to boot until it is ready to run your application is measured in minutes, whereas in Docker a container can boot in sub-second times.</p>
<h2>Building Docker images with uberimage</h2>
<p><code>lein-uberimage</code> builds a Docker image for clojure projects. The generated images contain a base operating system, a java runtime, and your project's <code>uberjar</code>. Once this image is built, you can instantiate as many containers as you need using this image, each container running your <code>uberjar</code>.</p>
<p>At the time of writing this, <code>lein-uberimage</code> requires that the project builds with <code>lein uberjar</code> and that the resulting jar can be run via <code>java -jar <your-uberjar>.jar</code>. This means your <code>project.clj</code> will have to have a <code>:main</code> entry pointing to the <code>-main</code> function in your code. This restriction will be removed in the future.</p>
<p>To build the Docker image for your project, run the following in your project's root:</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>lein uberimage
</code></pre></div>
<p><code>uberimage</code> will call lein's <code>uberjar</code> to build the standalone jar file. Then it will build a new image with <code>Ubuntu 14.04</code>, <code>OpenJDK 7</code> and the freshly built jar. The image is also configured to run your jar file on boot. This task will return the <code>uuid</code> for this image.</p>
<p>From this image you just created, you can spawn as many containers as you need. The most basic way to start a container is this:</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>docker run <my-image-uuid>
</code></pre></div>
<p>In most cases, your app won't be useful unless you can access it via known ports, and by default, Docker does not expose any ports of a container, so you need to tell Docker to expose those ports. Since you will be running many containers on the same host you need to ensure that not two containers are bound to the same port. For example, if your application listens on port 3000, you need to tell Docker to bind the container's port 3000 to any unbound port in the host, e.g. 8080:</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>docker run -p 8080:3000 <my-image-uuid>
</code></pre></div>
<p>Once the container has started, just head over to <code>http://<docker-host>:8080</code> to access your newly deployed service. If you launch a second container with the same image, you cannot bind it to the same host port (8080 in this case) and you should instead map it to port 8081 <code>docker run -p 8081:3000 ...</code>.</p>
<h2>Trying It Out</h2>
<ul>
<li><a href="https://docs.docker.com/installation/#installation">Install</a> Docker.</li>
<li>Clone this <a href="https://github.com/tbatchelli/compojure-example">example clojure project</a>.</li>
<li>On the project root, run <code>lein uberimage</code> and copy the supplied image uuid</li>
<li>At the shell, run <code>docker run -d -p 3000:3000 <image-uuid></code></li>
<li>Open the browser and head on to <code>http://<docker-host>:3000</code>. Docker-host could be <code>localhost</code> in case you are in linux, or the boot2docker IP address if you are using boot2docker.</li>
<li>Run <code>docker run -d -p 3001:3000 <image-uuid></code> to run a second instance and check <code>http://<docker-host>:3001</code> with your browser. Notice the different IP address.</li>
</ul>
<h2>Additional Options</h2>
<p>In case the supplied OS and java versions are not what you're looking for, you can supply your own base image to <code>lein-uberimage</code>:</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>lein uberimage -b <your-image-with-jvm>
</code></pre></div>
<p>And in case your Docker is not locally installed on the default port or it is remote, you can override its url:</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>lein uberimage -H http://<host>:<port>
</code></pre></div>
<h2>Concluding remarks</h2>
<p>There is not much more to it for now. This is our first stab at helping clojurians leverage containers. Please submit bugs and ideas to our project's <a href="https://github.com/palletops/lein-uberimage/issues">Issues</a> or drop by our chatroom <a href="http://webchat.freenode.net/?channels=pallet">#pallet</a> on freenode.</p>
<p><code>lein-uberimage</code> is build on top of <a href="https://github.com/palletops/clj-docker.">clj-docker</a>, a clojure wrapper over docker.</p>
</div>
<div class="post-call-us">
<p><em>
Are you working on speeding up your development to production
pathways and enhance the reliability of your online services?
We at PalletOps provide consulting services specializing in infrastructure
automation, both for cloud and non-cloud environments
and lightweight containers. Please <a href="/contact">contact us</a>
to see how our services can get you close to your goals.
</em></p>
</div>
<p class="text-muted post-meta"> This post was published on 07 August 2014
under the categories:
<a href="/blog/category/blog" style="text-decoration: none">
<span class="label label-primary">blog</span> </a>
<a href="/blog/category/docker" style="text-decoration: none">
<span class="label label-primary">docker</span> </a>
<a href="/blog/category/news" style="text-decoration: none">
<span class="label label-primary">news</span> </a>
</p>
<!-- This must be within a content class -->
<div class="panel panel-default post-share-panel">
<div class="panel-heading">
<h3 class="panel-title">Share this post:</h3>
</div> <!-- /.panel-heading-->
<div class="panel-body">
<ul class="list-inline">
<li> <a href="//twitter.com/intent/tweet?url=http%3A%2F%2Fpalletops.com%2F%2Fblog%2Flein-uberimage&text=Check+this+out%3A&hashtags=palletops">
<button class="btn btn-sm btn-twitter"><i class="fa
fa-twitter"></i> | Twitter</button> </a> </li>
<li><a href="http://linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fpalletops.com%2F%2Fblog%2Flein-uberimage&title=Run clojure projects on Docker with lein-uberimage&summary=We built a lein plugin to make it easy to run clojure projects in Docker containers. This article first introduces containers and Docker, and then shows how you can effortlessly create such containers for your Clojure projects with lein uberimage.
">
<button class="btn btn-sm btn-linkedin"><i class="fa
fa-linkedin"></i> | LinkedIn</button></a><li>
<li><a href="https://plus.google.com/share?url=http%3A%2F%2Fpalletops.com%2F%2Fblog%2Flein-uberimage"
<button class="btn btn-sm btn-google-plus">
<i class="fa fa-google-plus"></i> | Google+</button></a></li>
</ul>
</div> <!-- share row -->
</div>
<div class="panel panel-default post-comment-panel">
<div class="panel-heading"> <h3 class="panel-title">Discuss:</h3></div>
<div class="panel-body">
<div id="disqus_thread"></div>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div> <!-- /.panel-body -->
</div> <!-- /.panel-->
</div><!--content-->
<div class="col-md-3 col-xs-12 sidebar">
<h3>Connect with us:</h3>
<div class="pull-center">
<a href="https://twitter.com/intent/user?screen_name=PalletOps" target="_blank">
<button class="btn btn-sm btn-twitter"><i class="fa fa-twitter">
</i> | Connect with Twitter</button><br>
</a>
</div>
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="http://palletops.us8.list-manage.com/subscribe/post?u=2e50ddbe95bbf8b6396a32ac6&id=37bb0298a7"
method="post" id="mc-embedded-subscribe-form"
name="mc-embedded-subscribe-form" class="validate"
target="_blank" novalidate>
<div class="form-group">
<label for="mce-EMAIL">Subscribe to our mailing list:</label>
<input type="email" value="" name="EMAIL" class="form-control required email" id="mce-EMAIL"
placeholder="your@email.com">
</div> <!-- /.form-group -->
<div id="mce-responses">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;">
<input type="text" name="b_2e50ddbe95bbf8b6396a32ac6_37bb0298a7" tabindex="-1" value=""></div>
<div><input type="submit" value="Subscribe" name="subscribe"
id="mc-embedded-subscribe" class="btn btn-sm btn-default"></div>
</form>
</div>
<!--End mc_embed_signup-->
<div class="blog-tag">
<div id="tags">
<h3>Categories:</h3>
<!-- Warning! hardcoded link for /blog/category ... -->
<p><a href="/blog/category/blog" style="text-decoration: none">
<span class="label label-primary">blog | 10</span>
</a>
</p>
<!-- Warning! hardcoded link for /blog/category ... -->
<p><a href="/blog/category/docker" style="text-decoration: none">
<span class="label label-primary">docker | 1</span>
</a>
</p>
<!-- Warning! hardcoded link for /blog/category ... -->
<p><a href="/blog/category/news" style="text-decoration: none">
<span class="label label-primary">news | 6</span>
</a>
</p>
</div>
</div>
</div><!-- /.sidebar -->
</div><!-- /.row -->
</div> <!-- /.container -->
</div>
<footer class="footer">
<div class="container">
<div class="row">
<div class="col-md-5">
<h4>About</h4>
<p>Pallet is an open source DevOps library for the JVM,
built on Clojure, with native support for clusters, node
dependencies and agile development.</p>
<p></p>
<p>Infrastructure generously provided by:</p>
<p>
<a href="http://rackspace.com">
<img src="http://67516654d2ef99c3042d-b9d92f522aee852c07f26ce9d1459c9c.r8.cf1.rackcdn.com/20140625-01/images/rackspace-logo.png" alt="Rackspace Logo"></img>
</a></p>
</div>
<div class="col-md-3 col-xs-6 col-md-offset-1">
<h4>Site Map</h4>
<ul>
<li class=" " >
<a href="/pallet/doc">
Documentation
</a>
</li>
<li class="active " >
<a href="/blog">
Blog
</a>
</li>
<li class=" " >
<a href="/services">
Services
</a>
</li>
<li class=" hidden-sm hidden-xm" >
<a href="/support">
Support
</a>
</li>
<li class=" hidden-sm hidden-xm" >
<a href="/contact">
Contact
</a>
</li>
<li class=" hidden-sm hidden-xs" >
<a href="https://github.com/pallet/pallet">
<i class="fa fa-github"></i> Code
</a>
</li>
</ul>
</div>
<div class="col-md-3 col-xs-6">
<h4>Contact</h4>
<ul>
<li><a href="/contact"><i class="fa fa-pencil-square-o"></i> Contact Form</a></li>
<li><a href="/support"><i class="fa fa-info-circle"></i> Get Support</a></li>
<li><a href="mailto:contact@palletops.com"><i class="fa fa-envelope-o"></i> contact@palletops.com</a></li>
<li><a href="https://twitter.com/intent/user?screen_name=PalletOps" target="_blank"><i class="fa fa-twitter"></i> twitter</a></li>
</ul>
</div>
</div> <!-- row -->
<div class="row footer-footer">
<div class="col-sm-12">
<p>
Copyright © 2014 Hugo Duncan and Antoni Batchelli
</p>
<p class="text-muted">
<small>Built with <a target="_blank"
href="http://jekyllrb.com">Jekyll</a> and
<a target="_blank" href="http://getbootstrap.com">Bootstrap</a> on
Mon, 22 Sep 2014 14:01:57 +0000</small></p>
</div>
</div> <!-- /.row -->
</div>
</footer>
<!-- Latest compiled and minified JavaScript -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-19685457-1', 'palletops.com');
ga('send', 'pageview');
</script>
<script type="text/javascript">
var disqus_shortname = 'palletops'; // required: replace example with your forum shortname
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<!-- begin olark code -->
<script data-cfasync="false" type='text/javascript'>/*<![CDATA[*/window.olark||(function(c){var f=window,d=document,l=f.location.protocol=="https:"?"https:":"http:",z=c.name,r="load";var nt=function(){
f[z]=function(){
(a.s=a.s||[]).push(arguments)};var a=f[z]._={
},q=c.methods.length;while(q--){(function(n){f[z][n]=function(){
f[z]("call",n,arguments)}})(c.methods[q])}a.l=c.loader;a.i=nt;a.p={
0:+new Date};a.P=function(u){
a.p[u]=new Date-a.p[0]};function s(){
a.P(r);f[z](r)}f.addEventListener?f.addEventListener(r,s,false):f.attachEvent("on"+r,s);var ld=function(){function p(hd){
hd="head";return["<",hd,"></",hd,"><",i,' onl' + 'oad="var d=',g,";d.getElementsByTagName('head')[0].",j,"(d.",h,"('script')).",k,"='",l,"//",a.l,"'",'"',"></",i,">"].join("")}var i="body",m=d[i];if(!m){
return setTimeout(ld,100)}a.P(1);var j="appendChild",h="createElement",k="src",n=d[h]("div"),v=n[j](d[h](z)),b=d[h]("iframe"),g="document",e="domain",o;n.style.display="none";m.insertBefore(n,m.firstChild).id=z;b.frameBorder="0";b.id=z+"-loader";if(/MSIE[ ]+6/.test(navigator.userAgent)){
b.src="javascript:false"}b.allowTransparency="true";v[j](b);try{
b.contentWindow[g].open()}catch(w){
c[e]=d[e];o="javascript:var d="+g+".open();d.domain='"+d.domain+"';";b[k]=o+"void(0);"}try{
var t=b.contentWindow[g];t.write(p());t.close()}catch(x){
b[k]=o+'d.write("'+p().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}a.P(2)};ld()};nt()})({
loader: "static.olark.com/jsclient/loader0.js",name:"olark",methods:["configure","extend","declare","identify"]});
/* custom configuration goes here (www.olark.com/documentation) */
olark.identify('9249-736-10-9825');/*]]>*/</script><noscript><a href="https://www.olark.com/site/9249-736-10-9825/contact" title="Contact us" target="_blank">Questions? Feedback?</a> powered by <a href="http://www.olark.com?welcome" title="Olark live chat software">Olark live chat software</a></noscript>
<!-- end olark code -->
</body>
</html>