-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap-image.html
791 lines (458 loc) · 45.1 KB
/
bootstrap-image.html
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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content=" Getting Started with Bootstrap Bootstrapping a ContainerBootstrapping is the process where we install an operating system and then configure it appropriately for a specified need. To do this we use a bootstrap definition file (a text file called Singularity) which is a recipe of how to specifically build the container. Here we will overview the sections, best practices, and a quick example.Quick StartToo long… didn’t read! If you want the quickest way to run bootstrap, here is the usage:$ singularity bootstrapUSAGE: singularity [...] bootstrap <container path> <definition file>The <container path> is the path to the Singularity image file, and the <definition file> is the location of the definition file (the recipe) we will use to create this container. The process of building a container should always be done by root so that the correct file ownership and permissions are maintained. Also, so installation programs check to ensure they are the root user before proceeding. The bootstrap process may take anywhere from one minute to one hour depending on what needs to be done and how fast your network connection is.Let’s continue with our quick start example. Here is your spec file, Singularity,Bootstrap:dockerFrom:ubuntu:latestYou next create an image:$ singularity create ubuntu.imgInitializing Singularity image subsystemOpening image file: ubuntu.imgCreating 768MiB imageBinding image to loopCreating file system within imageImage is done: ubuntu.imgand finally run the bootstrap command, pointing to your image (<container path>) and the file Singularity (<definition file>).$ sudo singularity bootstrap ubuntu.img Singularity Sanitizing environmentBuilding from bootstrap definition recipeAdding base Singularity environment to containerDocker image path: index.docker.io/library/ubuntu:latestCache folder set to /root/.singularity/docker[5/5] |===================================| 100.0% Exploding layer: sha256:b6f892c0043b37bd1834a4a1b7d68fe6421c6acbc7e7e63a4527e1d379f92c1b.tar.gzExploding layer: sha256:55010f332b047687e081a9639fac04918552c144bc2da4edb3422ce8efcc1fb1.tar.gzExploding layer: sha256:2955fb827c947b782af190a759805d229cfebc75978dba2d01b4a59e6a333845.tar.gzExploding layer: sha256:3deef3fcbd3072b45771bd0d192d4e5ff2b7310b99ea92bce062e01097953505.tar.gzExploding layer: sha256:cf9722e506aada1109f5c00a9ba542a81c9e109606c01c81f5991b1f93de7b66.tar.gzExploding layer: sha256:fe44851d529f465f9aa107b32351c8a0a722fc0619a2a7c22b058084fac068a4.tar.gzFinalizing Singularity containerNotice that bootstrap does require sudo. If you do an import, with a docker uri for example, you would see a similar flow, but the calling user would be you, and the cache your $HOME.$singularity create ubuntu.imgsingularity import ubuntu.img docker://ubuntu:latestDocker image path: index.docker.io/library/ubuntu:latestCache folder set to /home/vanessa/.singularity/dockerImporting: base Singularity environmentImporting: /home/vanessa/.singularity/docker/sha256:b6f892c0043b37bd1834a4a1b7d68fe6421c6acbc7e7e63a4527e1d379f92c1b.tar.gzImporting: /home/vanessa/.singularity/docker/sha256:55010f332b047687e081a9639fac04918552c144bc2da4edb3422ce8efcc1fb1.tar.gzImporting: /home/vanessa/.singularity/docker/sha256:2955fb827c947b782af190a759805d229cfebc75978dba2d01b4a59e6a333845.tar.gzImporting: /home/vanessa/.singularity/docker/sha256:3deef3fcbd3072b45771bd0d192d4e5ff2b7310b99ea92bce062e01097953505.tar.gzImporting: /home/vanessa/.singularity/docker/sha256:cf9722e506aada1109f5c00a9ba542a81c9e109606c01c81f5991b1f93de7b66.tar.gzImporting: /home/vanessa/.singularity/metadata/sha256:fe44851d529f465f9aa107b32351c8a0a722fc0619a2a7c22b058084fac068a4.tar.gzBest Practices for BootstrappingWhen bootstrapping a container, it is best to consider the following: Install packages, programs, data, and files into operating system locations (e.g. not /home, /tmp, or any other directories that might get commonly binded on). If you require any special environment variables to be defined, add them the /environment file inside the container. Files should never be owned by actual users, they should always be owned by a system account (UID < 500). Ensure that the container’s /etc/passwd, /etc/group, /etc/shadow, and no other sensitive files have anything but the bare essentials within them. Do all of your bootstrapping via a definition file instead of manipulating the containers by hand (with the --writable options), this ensures greatest possibility of reproducibility and mitigates the black box effect.The Bootstrap Definition FileThere are multiple sections of the Singularity bootstrap definition file: Header: The Header describes the core operating system to bootstrap within the container. Here you will configure the base operating system features that you need within your container. Examples of this include, what distribution of Linux, what version, what packages must be part of a core install. Sections: The rest of the definition is comprised of sections or blobs of data. Each section is defined by a % character followed by the name of the particular section. All sections are optional.HeaderThe header is at the top of the file, and tells Singularity the kind of bootstrap, and from where. For example, a very minimal Docker bootstrap might look like this:Bootstrap: dockerFrom: ubuntu:latesta Bootstrap that uses a mirror to install Centos-7 might look like this:BootStrap: yumOSVersion: 7MirrorURL: http://mirror.centos.org/centos-%{OSVERSION}/%{OSVERSION}/os/$basearch/Include: yumFor complete details about header fields that are allowed, please see the Bootstrap Command. We will continue here with higher level overview.SectionsThe main content of the bootstrap file is broken into sections.%setupSetup is where you might perform actions on the host before we move into the container. For versions earlier than 2.3, you would copy files from your host to $SINGULARITY_ROOTFS to move them into the container. For 2.3 and later, we recommend you use %files. We can see the difference between %setup and %post in the following asciicast:Show Video Tutorial In the above, we see that copying something to $SINGULARITY_ROOTFS during %setup was successful to move the file into the container, but copying during %post was not.%filesSpeaking of files, if you want to copy content into the container, you should do so using the %files section, where each is a pair of <source> and <destination>, where the file or expression to be copied is a path on your host, and the destination is a path in the container. Here we are using the traditional cp command, so the same conventions apply.%labelsTo store metadata with your container, you can add them to the %labels section. They will be stored in a file /.singularity.d/labels.json as metadata with your container. The general format is a LABELNAME followed by a LABELVALUE. Labels from Docker bootstraps will be carried forward here. As an example:%labelsMaintainer [email protected] 2.0%environmentAkin to labels, you can add pairs of VARIABLE and VALUE under environment to be sourced when the container is used as variables in the environment. The entire section is written to a file that gets sourced, so you should generally use the same conventions that you might use in a bashrc or profile. See Environment and Metadata for more information about these two sections.%postThis scriptlet will be run from inside the container. This is where the guts of your setup will live, including making directories, and installing software and libraries. For example, here we are installing yum, openMPI, and other dependencies for a Centos7 bootstrap:%post echo "Installing Development Tools YUM group" yum -y groupinstall "Development Tools" echo "Installing OpenMPI into container..." # Here we are at the base, /, of the container git clone https://github.com/open-mpi/ompi.git # Now at /ompi cd ompi ./autogen.pl ./configure --prefix=/usr/local make make install /usr/local/bin/mpicc examples/ring_c.c -o /usr/bin/mpi_ringYou cannot copy files from the host to your container in this section, but you can of course download with commands like git clone and wget and curl.%runscriptThe %runscript is another scriptlet, but it does not get executed during bootstrapping. Instead it gets persisted within the container to a file called /singularity which is the execution driver when the container image is run (either via the singularity run command or via executing the container directly).When the %runscript is executed, all options are passed along to the executing script at runtime, this means that you can (and should) manage argument processing from within your runscript. Here is an example of how to do that:%runscript echo "Arguments received: $*" exec /usr/bin/python "$@"In this particular runscript, the arguments are printed as a single string ($*) and then they are passed to /usr/bin/python via a quoted array ($@) which ensures that all of the arguments are properly parsed by the executed command. The exec command causes the given command to replace the current entry in the process table with the one that is to be called. This makes it so the runscript shell process ceases to exist, and the only process running inside this container is the called Python command.%testYou may choose to add a %test section to your definition file. This section will be run at the very end of the boostrapping process and will give you a chance to validate the container during the bootstrap process. You can also execute this scriptlet through the container itself, such that you can always test the validity of the container itself as you transport it to different hosts. Extending on the above Open MPI %post, consider this example:%test /usr/local/bin/mpirun --allow-run-as-root /usr/bin/mpi_testThis is a simple Open MPI test to ensure that the MPI is build properly and communicates between processes as it should.If you want to bootstrap without running tests, you can do so with the --notest argument:$ sudo singularity bootstrap --notest container.img SingularityThis argument might be useful in cases where you might need hardware that is available during runtime, but is not available on the host that is building the image.ExamplesFor more examples, we recommend you look at other containers on Singularity Hub. For more examples we recommend that you look at the examples folder for the most up-to-date examples. Previous Next Edit me Site last generated: Jul 26, 2017 ">
<meta name="name" content="Getting Started with Bootstrap">
<meta name="thumbnail" content="http://singularity.lbl.gov/images/logo/logo.svg">
<title>Getting Started with Bootstrap | Singularity</title>
<link rel="stylesheet" href="assets/css/syntax.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">-->
<link rel="stylesheet" href="assets/css/modern-business.css">
<link rel="stylesheet" href="assets/css/lavish-bootstrap.css">
<link rel="stylesheet" href="assets/css/customstyles.css">
<link rel="stylesheet" href="assets/css/theme-blue.css">
<link rel="stylesheet" type="text/css" href="assets/css/asciinema-player.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="assets/js/jquery.navgoco.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/2.0.0/anchor.min.js"></script>
<script src="assets/js/toc.js"></script>
<script src="assets/js/customscripts.js"></script>
<link rel="shortcut icon" href="images/favicon/favicon.ico">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="alternate" type="application/rss+xml" title="" href="http://localhost:4005feed.xml">
<script>
$(document).ready(function() {
// Initialize navgoco with default options
$("#mysidebar").navgoco({
caretHtml: '',
accordion: true,
openClass: 'active', // open
save: false, // leave false or nav highlighting doesn't work right
cookie: {
name: 'navgoco',
expires: false,
path: '/'
},
slide: {
duration: 400,
easing: 'swing'
}
});
$("#collapseAll").click(function(e) {
e.preventDefault();
$("#mysidebar").navgoco('toggle', false);
});
$("#expandAll").click(function(e) {
e.preventDefault();
$("#mysidebar").navgoco('toggle', true);
});
});
</script>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
</head>
<body>
<!-- asciinema player -->
<script src="assets/js/asciinema-player.js"></script>
<!-- Show or hide players on button clicks-->
<script>
$( document ).ready(function() {
$(".asciinema-button").click(function(){
var asciinemaVideo = "#asciinema-" + $(this).attr('id');
if ($(asciinemaVideo).hasClass('hidden')){
$(asciinemaVideo).removeClass('hidden');
$(this).text('Hide Tutorial')
} else {
$(asciinemaVideo).addClass('hidden');
$(this).text('Show Tutorial')
}
});
});
</script>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container topnavlinks">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<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="index.html"> <span class="projectTitle"> Singularity</span></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<!-- entries without drop-downs appear here -->
<li><a href="blog">News</a></li>
<!-- entries with drop-downs appear here -->
<!-- conditional logic to control which topnav appears for the audience defined in the configuration file.-->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Docs<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="admin-guide">Admin Guide</a></li>
<li><a href="user-guide">User Guide</a></li>
<li><a href="links">Contributed Content</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Quick Links<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="https://github.com/singularityware/singularity" target="_blank">Github Repo</a></li>
<li><a href="https://groups.google.com/a/lbl.gov/forum/#!forum/singularity" target="_blank">Google Group</a></li>
<li><a href="http://stackoverflow.com/questions/tagged/singularity" target="_blank">Singularity on Stack Overflow</a></li>
<li><a href="https://singularity-hub.org/faq" target="_blank">Singularity Hub</a></li>
<li><a href="https://singularity-container.slack.com" target="_blank">Slack</a></li>
<li><a href="faq#troubleshooting">Troubleshooting</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">People<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="https://github.com/gmkurtzer" target="_blank">Gregory M. Kurtzer</a></li>
<li><a href="https://github.com/vsoch" target="_blank">Vanessa Sochat</a></li>
<li><a href="https://github.com/bauerm97" target="_blank">Michael Bauer</a></li>
<li><a href="https://github.com/bbockelm" target="_blank">Brian Bockelman</a></li>
<li><a href="https://github.com/singularityware/singularity/blob/master/AUTHORS" target="_blank">Complete Authors List</a></li>
</ul>
</li>
<li><a href="/search"><i class="fa fa-search"></i></li>
<!-- jekyll search hidden in favor of google
<li>
<div id="search-demo-container">
<input type="text" id="search-input" placeholder="search...">
<ul id="results-container"></ul>
</div>
<script src="assets/js/jekyll-search.js" type="text/javascript"></script>
<script type="text/javascript">
SimpleJekyllSearch.init({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
dataSource: 'search.json',
searchResultTemplate: '<li><a href="{url}" title="Getting Started with Bootstrap">{title}</a></li>',
noResultsText: 'No results found.',
limit: 10,
fuzzy: true,
})
</script>
end search-->
</li>
</ul>
</div>
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<div class="col-lg-12"> </div>
<!-- Content Row -->
<div class="row">
<!-- Sidebar Column -->
<div class="col-md-3">
<div class="shiny"><a href="\"><figure><img src="/images/logo/logo.svg" class="sidebar-logo"/></figure></a></div>
<ul id="mysidebar" class="nav">
<li class="sidebarTitle">User Guide</li>
<li>
<a href="#">Getting Started</a>
<ul>
<li><a href="user-guide">Introduction</a></li>
<li><a href="docs-quick-start-installation">Quick Start Installation</a></li>
<li><a href="create-image">Create an Image</a></li>
<li class="active"><a href="bootstrap-image">Bootstrap an Image</a></li>
<li><a href="docs-content">Adding Content</a></li>
<li><a href="docs-mount">Bind Paths and Files</a></li>
<li><a href="docs-environment-metadata">Environment and Metadata</a></li>
<li><a href="docs-changing-containers">Change an Existing Container</a></li>
<li><a href="docs-docker">Singularity and Docker</a></li>
<li><a href="faq#troubleshooting">Troubleshooting</a></li>
</ul>
<li>
<a href="#">Commands</a>
<ul>
<li><a href="docs-usage">Command Usage</a></li>
<li><a href="docs-bootstrap">bootstrap</a></li>
<li><a href="docs-exec">exec</a></li>
<li><a href="docs-export">export</a></li>
<li><a href="docs-import">import</a></li>
<li><a href="docs-inspect">inspect</a></li>
<li><a href="docs-pull">pull</a></li>
<li><a href="docs-run">run</a></li>
<li><a href="docs-shell">shell</a></li>
</ul>
<!-- if you aren't using the accordion, uncomment this block:
<p class="external">
<a href="#" id="collapseAll">Collapse All</a> | <a href="#" id="expandAll">Expand All</a>
</p>
-->
</li>
</ul>
</div>
<!-- this highlights the active parent class in the navgoco sidebar. this is critical so that the parent expands when you're viewing a page. This must appear below the sidebar code above. Otherwise, if placed inside customscripts.js, the script runs before the sidebar code runs and the class never gets inserted.-->
<script>$("li.active").parents('li').toggleClass("active");</script>
<!-- Content Column -->
<div class="col-md-9">
<div class="post-header">
<h1 class="post-title-main">Getting Started with Bootstrap</h1>
</div>
<div class="post-content">
<!-- Previous and next buttons-->
<div class="row" style="padding-top:30px; margin-bottom:10px"><div class="col-md-12">
<a href="#"><button style="float:left" class="hidden previous-button btn btn-circle btn-default"><i class="fa-2x fa fa-angle-double-left"></i></button></a>
<a href="#"><button style="float:right" class="hidden next-button btn btn-circle btn-default"><i class="fa fa-angle-double-right fa-2x"></i></button></a>
</div></div>
<script>
$(document).ready(function(){
var next = $("li.active").next().last().find('a').attr('href');
var previous = $("li.active").prev().last().find('a').attr('href');
// NEXT BUTTON
if (typeof next == 'undefined'){
console.log("disabling next button")
$(".next-button").addClass("hidden")
} else if (next == "#") {
next = $("li.active").next().find("li").first().find('a').attr('href');
$(".next-button").closest('a').attr('href', next)
$(".next-button").removeClass('hidden')
} else {
$(".next-button").closest('a').attr('href', next)
$(".next-button").removeClass('hidden')
}
// PREVIOUS BUTTON
if (typeof previous == 'undefined'){
console.log("disabling previous button")
$(".previous-button").addClass("hidden")
} else if (previous == "#") {
previous = $("li.active").prev().find("li").last().find('a').attr('href')
$(".previous-button").closest('a').attr('href', previous)
$(".previous-button").removeClass('hidden')
} else {
$(".previous-button").closest('a').attr('href', previous)
$(".previous-button").removeClass('hidden')
}
})
</script>
<!-- this handles the automatic toc. use ## for subheads to auto-generate the on-page minitoc. if you use html tags, you must supply an ID for the heading element in order for it to appear in the minitoc. -->
<script>
$( document ).ready(function() {
// Handler for .ready() called.
$('#toc').toc({ minimumHeaders: 0, listType: 'ul', showSpeed: 0, headers: 'h2,h3,h4' });
/* this offset helps account for the space taken up by the floating toolbar. */
$('#toc').on('click', 'a', function() {
var target = $(this.getAttribute('href'))
, scroll_target = target.offset().top
$(window).scrollTop(scroll_target - 10);
return false
})
});
</script>
<div id="toc"></div>
<h2 id="bootstrapping-a-container">Bootstrapping a Container</h2>
<p>Bootstrapping is the process where we install an operating system and then configure it appropriately for a specified need. To do this we use a bootstrap definition file (a text file called <code class="highlighter-rouge">Singularity</code>) which is a recipe of how to specifically build the container. Here we will overview the sections, best practices, and a quick example.</p>
<!-- this handles the automatic toc. use ## for subheads to auto-generate the on-page minitoc. if you use html tags, you must supply an ID for the heading element in order for it to appear in the minitoc. -->
<script>
$( document ).ready(function() {
// Handler for .ready() called.
$('#toc').toc({ minimumHeaders: 0, listType: 'ul', showSpeed: 0, headers: 'h2,h3,h4' });
/* this offset helps account for the space taken up by the floating toolbar. */
$('#toc').on('click', 'a', function() {
var target = $(this.getAttribute('href'))
, scroll_target = target.offset().top
$(window).scrollTop(scroll_target - 10);
return false
})
});
</script>
<div id="toc"></div>
<h2 id="quick-start">Quick Start</h2>
<p>Too long… didn’t read! If you want the quickest way to run bootstrap, here is the usage:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>singularity bootstrap
USAGE: singularity <span class="o">[</span>...] bootstrap <container path> <definition file>
</code></pre>
</div>
<p>The <code class="highlighter-rouge"><container path></code> is the path to the Singularity image file, and the <code class="highlighter-rouge"><definition file></code> is the location of the definition file (the recipe) we will use to create this container. The process of building a container should always be done by root so that the correct file ownership and permissions are maintained. Also, so installation programs check to ensure they are the root user before proceeding. The bootstrap process may take anywhere from one minute to one hour depending on what needs to be done and how fast your network connection is.</p>
<p>Let’s continue with our quick start example. Here is your spec file, <code class="highlighter-rouge">Singularity</code>,</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>Bootstrap:docker
From:ubuntu:latest
</code></pre>
</div>
<p>You next create an image:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>singularity create ubuntu.img
Initializing Singularity image subsystem
Opening image file: ubuntu.img
Creating 768MiB image
Binding image to loop
Creating file system within image
Image is <span class="k">done</span>: ubuntu.img
</code></pre>
</div>
<p>and finally run the bootstrap command, pointing to your image (<code class="highlighter-rouge"><container path></code>) and the file <code class="highlighter-rouge">Singularity</code> (<code class="highlighter-rouge"><definition file></code>).</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>sudo singularity bootstrap ubuntu.img Singularity
Sanitizing environment
Building from bootstrap definition recipe
Adding base Singularity environment to container
Docker image path: index.docker.io/library/ubuntu:latest
Cache folder <span class="nb">set </span>to /root/.singularity/docker
<span class="o">[</span>5/5] |<span class="o">===================================</span>| 100.0%
Exploding layer: sha256:b6f892c0043b37bd1834a4a1b7d68fe6421c6acbc7e7e63a4527e1d379f92c1b.tar.gz
Exploding layer: sha256:55010f332b047687e081a9639fac04918552c144bc2da4edb3422ce8efcc1fb1.tar.gz
Exploding layer: sha256:2955fb827c947b782af190a759805d229cfebc75978dba2d01b4a59e6a333845.tar.gz
Exploding layer: sha256:3deef3fcbd3072b45771bd0d192d4e5ff2b7310b99ea92bce062e01097953505.tar.gz
Exploding layer: sha256:cf9722e506aada1109f5c00a9ba542a81c9e109606c01c81f5991b1f93de7b66.tar.gz
Exploding layer: sha256:fe44851d529f465f9aa107b32351c8a0a722fc0619a2a7c22b058084fac068a4.tar.gz
Finalizing Singularity container
</code></pre>
</div>
<p>Notice that bootstrap does require sudo. If you do an import, with a docker uri for example, you would see a similar flow, but the calling user would be you, and the cache your <code class="highlighter-rouge">$HOME</code>.</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="nv">$singularity</span> create ubuntu.img
singularity import ubuntu.img docker://ubuntu:latest
Docker image path: index.docker.io/library/ubuntu:latest
Cache folder <span class="nb">set </span>to /home/vanessa/.singularity/docker
Importing: base Singularity environment
Importing: /home/vanessa/.singularity/docker/sha256:b6f892c0043b37bd1834a4a1b7d68fe6421c6acbc7e7e63a4527e1d379f92c1b.tar.gz
Importing: /home/vanessa/.singularity/docker/sha256:55010f332b047687e081a9639fac04918552c144bc2da4edb3422ce8efcc1fb1.tar.gz
Importing: /home/vanessa/.singularity/docker/sha256:2955fb827c947b782af190a759805d229cfebc75978dba2d01b4a59e6a333845.tar.gz
Importing: /home/vanessa/.singularity/docker/sha256:3deef3fcbd3072b45771bd0d192d4e5ff2b7310b99ea92bce062e01097953505.tar.gz
Importing: /home/vanessa/.singularity/docker/sha256:cf9722e506aada1109f5c00a9ba542a81c9e109606c01c81f5991b1f93de7b66.tar.gz
Importing: /home/vanessa/.singularity/metadata/sha256:fe44851d529f465f9aa107b32351c8a0a722fc0619a2a7c22b058084fac068a4.tar.gz
</code></pre>
</div>
<h2 id="best-practices-for-bootstrapping">Best Practices for Bootstrapping</h2>
<p>When bootstrapping a container, it is best to consider the following:</p>
<ol>
<li>Install packages, programs, data, and files into operating system locations (e.g. not <code class="highlighter-rouge">/home</code>, <code class="highlighter-rouge">/tmp</code>, or any other directories that might get commonly binded on).</li>
<li>If you require any special environment variables to be defined, add them the <code class="highlighter-rouge">/environment</code> file inside the container.</li>
<li>Files should never be owned by actual users, they should always be owned by a system account (UID < 500).</li>
<li>Ensure that the container’s <code class="highlighter-rouge">/etc/passwd</code>, <code class="highlighter-rouge">/etc/group</code>, <code class="highlighter-rouge">/etc/shadow</code>, and no other sensitive files have anything but the bare essentials within them.</li>
<li>Do all of your bootstrapping via a definition file instead of manipulating the containers by hand (with the <code class="highlighter-rouge">--writable</code> options), this ensures greatest possibility of reproducibility and mitigates the <em>black box effect</em>.</li>
</ol>
<h2 id="the-bootstrap-definition-file">The Bootstrap Definition File</h2>
<p>There are multiple sections of the Singularity bootstrap definition file:</p>
<ol>
<li><strong>Header</strong>: The Header describes the core operating system to bootstrap within the container. Here you will configure the base operating system features that you need within your container. Examples of this include, what distribution of Linux, what version, what packages must be part of a core install.</li>
<li><strong>Sections</strong>: The rest of the definition is comprised of sections or blobs of data. Each section is defined by a <code class="highlighter-rouge">%</code> character followed by the name of the particular section. All sections are optional.</li>
</ol>
<h3 id="header">Header</h3>
<p>The header is at the top of the file, and tells Singularity the kind of bootstrap, and from where. For example, a very minimal Docker bootstrap might look like this:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>Bootstrap: docker
From: ubuntu:latest
</code></pre>
</div>
<p>a Bootstrap that uses a mirror to install Centos-7 might look like this:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>BootStrap: yum
OSVersion: 7
MirrorURL: http://mirror.centos.org/centos-%<span class="o">{</span>OSVERSION<span class="o">}</span>/%<span class="o">{</span>OSVERSION<span class="o">}</span>/os/<span class="nv">$basearch</span>/
Include: yum
</code></pre>
</div>
<p>For complete details about header fields that are allowed, please see the <a href="/docs-bootstrap">Bootstrap Command</a>. We will continue here with higher level overview.</p>
<h3 id="sections">Sections</h3>
<p>The main content of the bootstrap file is broken into sections.</p>
<h4 id="setup">%setup</h4>
<p>Setup is where you might perform actions on the host before we move into the container. For versions earlier than 2.3, you would copy files from your host to <code class="highlighter-rouge">$SINGULARITY_ROOTFS</code> to move them into the container. For 2.3 and later, we recommend you use <code class="highlighter-rouge">%files</code>. We can see the difference between <code class="highlighter-rouge">%setup</code> and <code class="highlighter-rouge">%post</code> in the following asciicast:</p>
<p><button style="color:white;margin-top:5px" class="btn btn-primary btn-lg asciinema-button" id="How-does-the-container-see-setup-vs-post?">Show Video Tutorial</button></p>
<div class="hidden" id="asciinema-How-does-the-container-see-setup-vs-post?">
<asciinema-player src="assets/asciicast/docs-bootstrap-setup-vs-post.json" poster="data:text/plain,How does the container see setup vs post?" title="How does the container see setup vs post?" author="[email protected]" cols="115" rows="25" speed="2.0" theme="asciinema">
</asciinema-player>
</div>
<p>In the above, we see that copying something to <code class="highlighter-rouge">$SINGULARITY_ROOTFS</code> during <code class="highlighter-rouge">%setup</code> was successful to move the file into the container, but copying during <code class="highlighter-rouge">%post</code> was not.</p>
<h4 id="files">%files</h4>
<p>Speaking of files, if you want to copy content into the container, you should do so using the <code class="highlighter-rouge">%files</code> section, where each is a pair of <code class="highlighter-rouge"><source></code> and <code class="highlighter-rouge"><destination></code>, where the file or expression to be copied is a path on your host, and the destination is a path in the container. Here we are using the traditional <code class="highlighter-rouge">cp</code> command, so the <a href="https://linux.die.net/man/1/cp" target="_blank">same conventions apply</a>.</p>
<h4 id="labels">%labels</h4>
<p>To store metadata with your container, you can add them to the <code class="highlighter-rouge">%labels</code> section. They will be stored in a file <code class="highlighter-rouge">/.singularity.d/labels.json</code> as metadata with your container. The general format is a <code class="highlighter-rouge">LABELNAME</code> followed by a <code class="highlighter-rouge">LABELVALUE</code>. Labels from Docker bootstraps will be carried forward here. As an example:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>%labels
Maintainer [email protected]
Version 2.0
</code></pre>
</div>
<h4 id="environment">%environment</h4>
<p>Akin to labels, you can add pairs of <code class="highlighter-rouge">VARIABLE</code> and <code class="highlighter-rouge">VALUE</code> under environment to be sourced when the container is used as variables in the environment. The entire section is written to a file that gets sourced, so you should generally use the same conventions that you might use in a <code class="highlighter-rouge">bashrc</code> or <code class="highlighter-rouge">profile</code>. See <a href="/docs-environment-metadata">Environment and Metadata</a> for more information about these two sections.</p>
<h4 id="post">%post</h4>
<p>This scriptlet will be run from inside the container. This is where the guts of your setup will live, including making directories, and installing software and libraries. For example, here we are installing yum, openMPI, and other dependencies for a Centos7 bootstrap:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>%post
<span class="nb">echo</span> <span class="s2">"Installing Development Tools YUM group"</span>
yum -y groupinstall <span class="s2">"Development Tools"</span>
<span class="nb">echo</span> <span class="s2">"Installing OpenMPI into container..."</span>
<span class="c"># Here we are at the base, /, of the container</span>
git clone https://github.com/open-mpi/ompi.git
<span class="c"># Now at /ompi</span>
<span class="nb">cd </span>ompi
./autogen.pl
./configure --prefix<span class="o">=</span>/usr/local
make
make install
/usr/local/bin/mpicc examples/ring_c.c -o /usr/bin/mpi_ring
</code></pre>
</div>
<p>You cannot copy files from the host to your container in this section, but you can of course download with commands like <code class="highlighter-rouge">git clone</code> and <code class="highlighter-rouge">wget</code> and <code class="highlighter-rouge">curl</code>.</p>
<h4 id="runscript">%runscript</h4>
<p>The <code class="highlighter-rouge">%runscript</code> is another scriptlet, but it does not get executed during bootstrapping. Instead it gets persisted within the container to a file called <code class="highlighter-rouge">/singularity</code> which is the execution driver when the container image is <strong><em>run</em></strong> (either via the <code class="highlighter-rouge">singularity run</code> command or via executing the container directly).</p>
<p>When the <code class="highlighter-rouge">%runscript</code> is executed, all options are passed along to the executing script at runtime, this means that you can (and should) manage argument processing from within your runscript. Here is an example of how to do that:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>%runscript
<span class="nb">echo</span> <span class="s2">"Arguments received: </span><span class="nv">$*</span><span class="s2">"</span>
<span class="nb">exec</span> /usr/bin/python <span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span>
</code></pre>
</div>
<p>In this particular runscript, the arguments are printed as a single string (<code class="highlighter-rouge">$*</code>) and then they are passed to <code class="highlighter-rouge">/usr/bin/python</code> via a quoted array (<code class="highlighter-rouge">$@</code>) which ensures that all of the arguments are properly parsed by the executed command. The <code class="highlighter-rouge">exec</code> command causes the given command to replace the current entry in the process table with the one that is to be called. This makes it so the runscript shell process ceases to exist, and the only process running inside this container is the called Python command.</p>
<h4 id="test">%test</h4>
<p>You may choose to add a <code class="highlighter-rouge">%test</code> section to your definition file. This section will be run at the very end of the boostrapping process and will give you a chance to validate the container during the bootstrap process. You can also execute this scriptlet through the container itself, such that you can always test the validity of the container itself as you transport it to different hosts. Extending on the above Open MPI <code class="highlighter-rouge">%post</code>, consider this example:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>%test
/usr/local/bin/mpirun --allow-run-as-root /usr/bin/mpi_test
</code></pre>
</div>
<p>This is a simple Open MPI test to ensure that the MPI is build properly and communicates between processes as it should.</p>
<p>If you want to bootstrap without running tests, you can do so with the <code class="highlighter-rouge">--notest</code> argument:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>sudo singularity bootstrap --notest container.img Singularity
</code></pre>
</div>
<p>This argument might be useful in cases where you might need hardware that is available during runtime, but is not available on the host that is building the image.</p>
<h2 id="examples">Examples</h2>
<p>For more examples, we recommend you look at other containers on <a href="https://singularity-hub.org" target="_blank">Singularity Hub</a>. For more <strong>examples</strong> we recommend that you look at the <a href="https://github.com/singularityware/singularity/tree/master/examples" target="_blank">examples</a> folder for the most up-to-date examples.</p>
<!-- More navigation on the bottom -->
<div class="row" style="padding-top:30px; margin-bottom:10px"><div class="col-md-12">
<a href="#"><button style="width:20%; height: 70px; float:left" class="hidden previous-button btn btn-lg btn-default">Previous</button></a>
<a href="#"><button style="width:20%; height: 70px; float:right" class="hidden next-button btn btn-lg btn-default">Next</button></a>
</div></div>
<a style="margin-top:10px;margin-bottom:10px" target="_blank" href="https://github.com/singularityware/singularityware.github.io/blob/master/pages/_pages/docs/bootstrap-image.md" class="btn btn-default btn-xs githubEditButton" role="button"><i class="fa fa-github fa-lg"></i> Edit me</a>
<div class="tags">
</div>
</div>
<hr class="shaded"/>
<footer>
<div class="row">
<!-- Social Media links, etc -->
<div class="col-lg-6 footer">
<a class="no-after social-icon" href="https://twitter.com/SingularityApp">
<i class="fa fa-4x fa-twitter no-after"></i>
</a>
<a class="no-after social-icon" href="https://github.com/singularityware">
<i class="fa fa-4x fa-github no-after"></i>
</a>
</div>
<div class="col-lg-6 footer">
<p><img src="images/logo/logo.png" alt="Company logo" style="width:40px;padding-bottom:10px"/></p>
Site last generated: Jul 26, 2017 <br />
</div>
</div>
</footer>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
</div>
</body>
<!-- the google_analytics_id gets auto inserted from the config file -->
<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-84672381-1','auto');ga('require','displayfeatures');ga('send','pageview');</script>
</html>