-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilding-ubuntu-rhel-host.html
704 lines (397 loc) · 35 KB
/
building-ubuntu-rhel-host.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
<!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=" Building an Ubuntu image on a RHEL host Sep 23, 2016 / This recipe describes how to build an Ubuntu image using Singularity on a RHEL compatible host.NOTE: this tutorial is intended for Singularity release 2.1.2, and reflects standards for that version.In order to do this, you will need to first install the ‘debootstrap’ package onto your host. Then, you will create a definition file that will describe how to build your Ubuntu image. Finally, you will build the image using the Singularity commands ‘create’ and bootstrap.PreparationThis recipe assumes that you have already installed Singularity on your computer. If you have not, follow the instructions here to install. After Singularity is installed on your computer, you will need to install the ‘debootstrap’ package. The ‘debootstrap’ package is a tool that will allow you to create Debian-based distributions such as Ubuntu. In order to install ‘debootstrap’, you will also need to install ‘epel-release’. You will need to download the appropriate RPM from the EPEL website. Make sure you download the correct version of the RPM for your release.# First, wget the appropriate RPM from the EPEL website (https://dl.fedoraproject.org/pub/epel/)# In this example we used RHEL 7, so we downloaded epel-release-latest-7.noarch.rpm$ wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm# Then, install your epel-release RPM$ sudo yum install epel-release-latest-7.noarch.rpm # Finally, install debootstrap$ sudo yum install debootstrapCreating the Definition FileYou will need to create a definition file to describe how to build your Ubuntu image. Definition files are plaintext files that contain Singularity keywords. By using certain Singularity keywords, you can specify how you want your image to be built. The extension ‘.def’ is recommended for user clarity. Below is a definition file for a minimal Ubuntu image: DistType "debian" MirrorURL "http://us.archive.ubuntu.com/ubuntu/" OSVersion "trusty" Setup Bootstrap Cleanup The following keywords were used in this definition file: DistType: DistType specifies the distribution type of your intended operating system. Because we are trying to build an Ubuntu image, the type “debian” was chosen. MirrorURL: The MirrorURL specifies the download link for your intended operating system. The Ubuntu archive website is a great mirror link to use if you are building an Ubuntu image. OSVersion: The OSVersion is used to specify which release of a Debian-based distribution you are using. In this example we chose “trusty” to specify that we wanted to build an Ubuntu 14.04 (Trusty Tahr) image. Setup: Setup creates some of the base files and components for an OS and is highly recommended to be included in your definition file. Bootstrap: Bootstrap will call apt-get to install the appropriate package to build your OS. Cleanup: Cleanup will remove temporary files from the installation.While this definition file is enough to create a working Ubuntu image, you may want increased customization of your image. There are several Singularity keywords that allow the user to do things such as install packages or files. Some of these keywords are used in the example below: DistType "debian" MirrorURL "http://us.archive.ubuntu.com/ubuntu/" OSVersion "trusty" Setup Bootstrap InstallPkgs python InstallPkgs wget RunCmd wget https://bootstrap.pypa.io/get-pip.py RunCmd python get-pip.py RunCmd ln -s /usr/local/bin/pip /usr/bin/pip RunCmd pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl CleanupBefore going over exactly what image this definition file specifies, the remaining Singularity keywords should be introduced. InstallPkgs: InstallPkgs allows you to install any packages that you want on your newly created image. InstallFile: InstallFile allows you to install files from your computer to the image. RunCmd: RunCmd allows you to run a command from within the new image during the installation. RunScript: RunScript adds a new line to the runscript invoked by the Singularity subcommand ‘run’. See the run page for more information.Now that you are familiar with all of the Singularity keywords, we can take a closer look at the example above. As with the previous example, an Ubuntu image is created with the specified DistType, MirrorURL, and OSVersion. However, after Setup and Bootstrap, we used the InstallPkgs keyword to install ‘python’ and ‘wget’. Then we used the RunCmd keyword to first download the pip installation wheel, and then to install ‘pip’. Subsequently, we also used RunCmd to pip install TensorFlow. Thus, we have created a definition file that will install ‘python’, ‘pip’, and ‘Tensorflow’ onto the new image.Creating your imageOnce you have created your definition file, you will be ready to actually create your image. You will do this by utilizing the Singularity ‘create’ and ‘bootstrap’ subcommands. The process for doing this can be seen below (note that we have saved our definition file as “ubuntu.def”):# First we will create an empty image container called ubuntu.img$ sudo singularity create ubuntu.imgCreating a sparse image with a maximum size of 1024MiB...INFO : Using given image size of 1024Formatting image (/sbin/mkfs.ext3)Done. Image can be found at: ubuntu.img # Next we will bootstrap the image with the operating system specified in our definition file$ sudo singularity bootstrap ubuntu.img ubuntu.defW: Cannot check Release signature; keyring file not available /usr/share/keyrings/ubuntu-archive-keyring.gpgI: Retrieving Release I: Retrieving Packages I: Validating Packages I: Resolving dependencies of required packages...I: Resolving dependencies of base packages...I: Found additional base dependencies: gcc-4.8-base gnupg gpgv libapt-pkg4.12 libreadline6 libstdc++6 libusb-0.1-4 readline-common ubuntu-keyring I: Checking component main on http://us.archive.ubuntu.com/ubuntu...I: Retrieving adduser 3.113+nmu3ubuntu3I: Validating adduser 3.113+nmu3ubuntu3I: Retrieving apt 1.0.1ubuntu2I: Validating apt 1.0.1ubuntu2snip...Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB) 100% |################################| 1.2MB 1.1MB/s Collecting setuptoolsDownloading setuptools-24.0.2-py2.py3-none-any.whl (441kB) 100% |################################| 450kB 2.7MB/s Collecting wheelDownloading wheel-0.29.0-py2.py3-none-any.whl (66kB) 100% |################################| 71kB 9.9MB/s Installing collected packages: pip, setuptools, wheelSuccessfully installed pip-8.1.2 setuptools-24.0.2 wheel-0.29.0At this point, you have successfully created an Ubuntu image with 'python', 'pip', and 'TensorFlow' on your RHEL computer.Tips and TricksHere are some tips and tricks that you can use to create more efficient definition files:Use here documents with RunCmdUsing here documents with conjunction with RunCmd can be a great way to decrease the number of RunCmd keywords that you need to include in your definition file. For example, we can substitute a here document into the previous example: DistType "debian" MirrorURL "http://us.archive.ubuntu.com/ubuntu/" OSVersion "trusty" Setup Bootstrap InstallPkgs python InstallPkgs wget RunCmd /bin/sh <<EOF wget https://bootstrap.pypa.io/get-pip.py python get-pip.py ln -s /usr/local/bin/pip /usr/bin/pip pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl EOF CleanupAs you can see, using a here document allowed us to decrease the number of RunCmd keywords from 4 to 1. This can be useful when your definition file has a lot of RunCmd keywords and can also ease copying and pasting command line recipes from other sources.Use InstallPkgs with multiple packagesThe InstallPkgs keyword is able to install multiple packages with a single keyword. Thus, another way you can increase the efficiency of your code is to use a single InstallPkgs keyword to install multiple packages, as seen below: DistType "debian" MirrorURL "http://us.archive.ubuntu.com/ubuntu/" OSVersion "trusty" Setup Bootstrap InstallPkgs python wget RunCmd /bin/sh <<EOF wget https://bootstrap.pypa.io/get-pip.py python get-pip.py ln -s /usr/local/bin/pip /usr/bin/pip pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl EOF CleanupUsing a single InstallPkgs keyword to install both ‘python’ and ‘wget’ allowed to decrease the number of InstallPkgs keywords we had to use in our definition file. This slimmed down our definition file and helped reduce clutter. Please enable JavaScript to view the comments powered by Disqus. Site last generated: Jul 26, 2017 ">
<meta name="keywords" content="recipes">
<meta name="name" content="Building an Ubuntu image on a RHEL host">
<meta name="thumbnail" content="http://singularity.lbl.gov/images/logo/logo.svg">
<title>Building an Ubuntu image on a RHEL host | 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 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="http://www.lbl.gov/" target="_blank">LBNL</a></li>
<li><a href="https://srcc.stanford.edu/" target="_blank">Stanford</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="Building an Ubuntu image on a RHEL host">{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">Singularity</li>
<li>
<a href="#">Information</a>
<ul>
<li><a href="blog">News</a></li>
<li><a href="about">About Singularity</a></li>
<li><a href="presentations">Presentations</a></li>
<li><a href="citation-registration">Registry: Citations and Installations</a></li>
</ul>
<li>
<a href="#">Download / Installation</a>
<ul>
<li><a href="all-releases">All Releases</a></li>
<li><a href="install-linux">Install Singularity on Linux</a></li>
<li><a href="install-mac">Install Singularity on Mac</a></li>
<li><a href="install-windows">Install Singularity on Windows</a></li>
</ul>
<li>
<a href="#">Contributing</a>
<ul>
<li><a href="contributing-support">User Support</a></li>
<li><a href="contributing-code">Code Development</a></li>
<li><a href="contributing-docs">Writing Documentation</a></li>
</ul>
<li>
<a href="#">Getting Help</a>
<ul>
<li><a href="faq">FAQ</a></li>
<li><a href="support">Support</a></li>
<li><a href="faq#troubleshooting">Troubleshooting</a></li>
</ul>
<li>
<a href="#">Documentation</a>
<ul>
<li><a href="quickstart">Quick Start</a></li>
<li><a href="tutorials">Recipes and Tutorials</a></li>
<li><a href="links">Contributed Content Links</a></li>
<li><a href="user-guide">User Documentation</a></li>
<li><a href="admin-guide">Admin Documentation</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">
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">Building an Ubuntu image on a RHEL host</h1>
<p class="post-meta"><time datetime="2016-09-23T00:00:00-04:00" itemprop="datePublished">Sep 23, 2016</time> /
</p>
</header>
<div class="post-content" itemprop="articleBody">
<p>This recipe describes how to build an Ubuntu image using Singularity on a RHEL compatible host.</p>
<p><strong>NOTE: this tutorial is intended for <a href="http://singularity.lbl.gov/release-2-1-2">Singularity release 2.1.2</a>, and reflects standards for that version.</strong></p>
<p>In order to do this, you will need to first install the ‘debootstrap’ package onto your host. Then, you will create a definition file that will describe how to build your Ubuntu image. Finally, you will build the image using the Singularity commands ‘create’ and <code class="highlighter-rouge">bootstrap</code>.</p>
<h2 id="preparation">Preparation</h2>
<p>This recipe assumes that you have already installed Singularity on your computer. If you have not, follow the instructions here to install. After Singularity is installed on your computer, you will need to install the ‘debootstrap’ package. The ‘debootstrap’ package is a tool that will allow you to create Debian-based distributions such as Ubuntu. In order to install ‘debootstrap’, you will also need to install ‘epel-release’. You will need to download the appropriate RPM from the EPEL website. Make sure you download the correct version of the RPM for your release.</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="c"># First, wget the appropriate RPM from the EPEL website (https://dl.fedoraproject.org/pub/epel/)</span>
<span class="c"># In this example we used RHEL 7, so we downloaded epel-release-latest-7.noarch.rpm</span>
<span class="gp">$ </span>wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
<span class="c"># Then, install your epel-release RPM</span>
<span class="gp">$ </span>sudo yum install epel-release-latest-7.noarch.rpm
<span class="c"># Finally, install debootstrap</span>
<span class="gp">$ </span>sudo yum install debootstrap
</code></pre>
</div>
<h3 id="creating-the-definition-file">Creating the Definition File</h3>
<p>You will need to create a definition file to describe how to build your Ubuntu image. Definition files are plaintext files that contain Singularity keywords. By using certain Singularity keywords, you can specify how you want your image to be built. The extension ‘.def’ is recommended for user clarity. Below is a definition file for a minimal Ubuntu image:</p>
<div class="highlighter-rouge"><pre class="highlight"><code> DistType "debian"
MirrorURL "http://us.archive.ubuntu.com/ubuntu/"
OSVersion "trusty"
Setup
Bootstrap
Cleanup
The following keywords were used in this definition file:
</code></pre>
</div>
<ul>
<li>DistType: DistType specifies the distribution type of your intended operating system. Because we are trying to build an Ubuntu image, the type “debian” was chosen.</li>
<li>MirrorURL: The MirrorURL specifies the download link for your intended operating system. The Ubuntu archive website is a great mirror link to use if you are building an Ubuntu image.</li>
<li>OSVersion: The OSVersion is used to specify which release of a Debian-based distribution you are using. In this example we chose “trusty” to specify that we wanted to build an Ubuntu 14.04 (Trusty Tahr) image.</li>
<li>Setup: Setup creates some of the base files and components for an OS and is highly recommended to be included in your definition file.</li>
<li>Bootstrap: Bootstrap will call apt-get to install the appropriate package to build your OS.</li>
<li>Cleanup: Cleanup will remove temporary files from the installation.</li>
</ul>
<p>While this definition file is enough to create a working Ubuntu image, you may want increased customization of your image. There are several Singularity keywords that allow the user to do things such as install packages or files. Some of these keywords are used in the example below:</p>
<div class="highlighter-rouge"><pre class="highlight"><code> DistType "debian"
MirrorURL "http://us.archive.ubuntu.com/ubuntu/"
OSVersion "trusty"
Setup
Bootstrap
InstallPkgs python
InstallPkgs wget
RunCmd wget https://bootstrap.pypa.io/get-pip.py
RunCmd python get-pip.py
RunCmd ln -s /usr/local/bin/pip /usr/bin/pip
RunCmd pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
Cleanup
</code></pre>
</div>
<p>Before going over exactly what image this definition file specifies, the remaining Singularity keywords should be introduced.</p>
<ul>
<li>InstallPkgs: InstallPkgs allows you to install any packages that you want on your newly created image.</li>
<li>InstallFile: InstallFile allows you to install files from your computer to the image.</li>
<li>RunCmd: RunCmd allows you to run a command from within the new image during the installation.</li>
<li>RunScript: RunScript adds a new line to the runscript invoked by the Singularity subcommand ‘run’. See the run page for more information.</li>
</ul>
<p>Now that you are familiar with all of the Singularity keywords, we can take a closer look at the example above. As with the previous example, an Ubuntu image is created with the specified DistType, MirrorURL, and OSVersion. However, after Setup and Bootstrap, we used the InstallPkgs keyword to install ‘python’ and ‘wget’. Then we used the RunCmd keyword to first download the pip installation wheel, and then to install ‘pip’. Subsequently, we also used RunCmd to pip install <code class="highlighter-rouge">TensorFlow</code>. Thus, we have created a definition file that will install ‘python’, ‘pip’, and ‘Tensorflow’ onto the new image.</p>
<h3 id="creating-your-image">Creating your image</h3>
<p>Once you have created your definition file, you will be ready to actually create your image. You will do this by utilizing the Singularity ‘create’ and ‘bootstrap’ subcommands. The process for doing this can be seen below (note that we have saved our definition file as “ubuntu.def”):</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="c"># First we will create an empty image container called ubuntu.img</span>
<span class="gp">$ </span>sudo singularity create ubuntu.img
Creating a sparse image with a maximum size of 1024MiB...
INFO : Using given image size of 1024
Formatting image <span class="o">(</span>/sbin/mkfs.ext3<span class="o">)</span>
Done. Image can be found at: ubuntu.img
<span class="c"># Next we will bootstrap the image with the operating system specified in our definition file</span>
<span class="gp">$ </span>sudo singularity bootstrap ubuntu.img ubuntu.def
W: Cannot check Release signature; keyring file not available /usr/share/keyrings/ubuntu-archive-keyring.gpg
I: Retrieving Release
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Found additional base dependencies: gcc-4.8-base gnupg gpgv libapt-pkg4.12 libreadline6 libstdc++6 libusb-0.1-4 readline-common ubuntu-keyring
I: Checking component main on http://us.archive.ubuntu.com/ubuntu...
I: Retrieving adduser 3.113+nmu3ubuntu3
I: Validating adduser 3.113+nmu3ubuntu3
I: Retrieving apt 1.0.1ubuntu2
I: Validating apt 1.0.1ubuntu2
snip...
Downloading pip-8.1.2-py2.py3-none-any.whl <span class="o">(</span>1.2MB<span class="o">)</span>
100% |################################| 1.2MB 1.1MB/s
Collecting setuptools
Downloading setuptools-24.0.2-py2.py3-none-any.whl <span class="o">(</span>441kB<span class="o">)</span>
100% |################################| 450kB 2.7MB/s
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl <span class="o">(</span>66kB<span class="o">)</span>
100% |################################| 71kB 9.9MB/s
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-8.1.2 setuptools-24.0.2 wheel-0.29.0
At this point, you have successfully created an Ubuntu image with <span class="s1">'python'</span>, <span class="s1">'pip'</span>, and <span class="s1">'TensorFlow'</span> on your RHEL computer.
Tips and Tricks
Here are some tips and tricks that you can use to create more efficient definition files:
</code></pre>
</div>
<h3 id="use-here-documents-with-runcmd">Use here documents with RunCmd</h3>
<p>Using here documents with conjunction with RunCmd can be a great way to decrease the number of RunCmd keywords that you need to include in your definition file. For example, we can substitute a here document into the previous example:</p>
<div class="highlighter-rouge"><pre class="highlight"><code> DistType "debian"
MirrorURL "http://us.archive.ubuntu.com/ubuntu/"
OSVersion "trusty"
Setup
Bootstrap
InstallPkgs python
InstallPkgs wget
RunCmd /bin/sh <<EOF
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
ln -s /usr/local/bin/pip /usr/bin/pip
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
EOF
Cleanup
</code></pre>
</div>
<p>As you can see, using a here document allowed us to decrease the number of RunCmd keywords from 4 to 1. This can be useful when your definition file has a lot of RunCmd keywords and can also ease copying and pasting command line recipes from other sources.</p>
<h3 id="use-installpkgs-with-multiple-packages">Use InstallPkgs with multiple packages</h3>
<p>The InstallPkgs keyword is able to install multiple packages with a single keyword. Thus, another way you can increase the efficiency of your code is to use a single InstallPkgs keyword to install multiple packages, as seen below:</p>
<div class="highlighter-rouge"><pre class="highlight"><code> DistType "debian"
MirrorURL "http://us.archive.ubuntu.com/ubuntu/"
OSVersion "trusty"
Setup
Bootstrap
InstallPkgs python wget
RunCmd /bin/sh <<EOF
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
ln -s /usr/local/bin/pip /usr/bin/pip
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
EOF
Cleanup
</code></pre>
</div>
<p>Using a single InstallPkgs keyword to install both ‘python’ and ‘wget’ allowed to decrease the number of InstallPkgs keywords we had to use in our definition file. This slimmed down our definition file and helped reduce clutter.</p>
</div>
<!--links to download are under archive before version 2.2-->
<!--links to download changed at version 2.2-->
</article>
<div id="disqus_thread" style="margin-top:30px"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'singularityware'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(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>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<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>