-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocs-exec.html
698 lines (397 loc) · 33.8 KB
/
docs-exec.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
<!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=" Singularity Exec The exec Singularity sub-command allows you to spawn an arbitrary command within your container image as if it were running directly on the host system. All standard IO, pipes, and file systems are accessible via the command being exec’ed within the container. Note that this exec is different from the Docker exec, as it does not require a container to be “running” before using it.UsageThe usage is as follows:USAGE: singularity [...] exec [exec options...] <container path> <command>This command will allow you to execute any program within the givencontainer image.EXEC OPTIONS: -B/--bind <spec> A user-bind path specification. spec has the format src[:dest[:opts]], where src and dest are outside and inside paths. If dest is not given, it is set equal to src. Mount options ('opts') may be specified as 'ro' (read-only) or 'rw' (read/write, which is the default). This option can be called multiple times. -c/--contain This option disables the automatic sharing of writable filesystems on your host (e.g. $HOME and /tmp). -C/--containall Contain not only file systems, but also PID and IPC -e/--cleanenv Clean environment before running container -H/--home <spec> A home directory specification. spec can either be a src path or src:dest pair. src is the source path of the home directory outside the container and dest overrides the home directory within the container -i/--ipc Run container in a new IPC namespace -p/--pid Run container in a new PID namespace --pwd Initial working directory for payload process inside the container -S/--scratch <path> Include a scratch directory within the container that is linked to a temporary dir (use -W to force location) -u/--user Try to run completely unprivileged (only works on very new kernels/distros) -W/--workdir Working directory to be used for /tmp, /var/tmp and $HOME (if -c/--contain was also used) -w/--writable By default all Singularity containers are available as read only. This option makes the file system accessible as read/write.CONTAINER FORMATS SUPPORTED: *.img This is the native Singularity image format for all Singularity versions 2.x. *.sqsh SquashFS format, note the suffix is required! *.tar* Tar archives are exploded to a temporary directory and run within that directory (and cleaned up after). Compression suffixes as '.gz' and 'bz2' are supported. directory/ Container directories that contain a valid root file system.EXAMPLES: $ singularity exec /tmp/Debian.img cat /etc/debian_version $ singularity exec /tmp/Debian.img python ./hello_world.py $ cat hello_world.py | singularity exec /tmp/Debian.img python $ sudo singularity exec --writable /tmp/Debian.img apt-get updateExamplesPrinting the OS release inside the container:$ singularity exec container.img cat /etc/os-releasePRETTY_NAME="Debian GNU/Linux 8 (jessie)"NAME="Debian GNU/Linux"VERSION_ID="8"VERSION="8 (jessie)"ID=debianHOME_URL="http://www.debian.org/"SUPPORT_URL="http://www.debian.org/support"BUG_REPORT_URL="https://bugs.debian.org/"$ Special CharactersAnd properly passing along special characters to the program within the container.$ singularity exec container.img echo -ne "hello\nworld\n\n"helloworld$ And a demonstration using pipes:$ cat debian.def | singularity exec container.img grep 'MirrorURL'MirrorURL "http://ftp.us.debian.org/debian/"$ A Python exampleStarting with the file hello.py in the current directory with the contents of:#!/usr/bin/pythonimport sysprint("Hello World: The Python version is %s.%s.%s" % sys.version_info[:3])Because our home directory is automatically bound into the container, and we are running this from our home directory, we can easily execute that script using the Python within the container:$ singularity exec /tmp/Centos7-ompi.img /usr/bin/python hello.py Hello World: The Python version is 2.7.5We can also pipe that script through the container and into the Python binary which exists inside the container using the following command:$ cat hello.py | singularity exec /tmp/Centos7-ompi.img /usr/bin/python Hello World: The Python version is 2.7.5For demonstration purposes, let’s also try to use the latest Python container which exists in DockerHub to run this script:$ singularity exec docker://python:latest /usr/local/bin/python hello.pylibrary/python:latestDownloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4Downloading layer: sha256:fbd06356349dd9fb6af91f98c398c0c5d05730a9996bbf88ff2f2067d59c70c4Downloading layer: sha256:644eaeceac9ff6195008c1e20dd693346c35b0b65b9a90b3bcba18ea4bcef071Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4Downloading layer: sha256:766692404ca72f4e31e248eb82f8eca6b2fcc15b22930ec50e3804cc3efe0abaDownloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4Downloading layer: sha256:6a3d69edbe90ef916e1ecd8d197f056de873ed08bcfd55a1cd0b43588f3dbb9aDownloading layer: sha256:ff18e19c2db42055e6f34323700737bde3c819b413997cddace2c1b7180d7efdDownloading layer: sha256:7b9457ec39de00bc70af1c9631b9ae6ede5a3ab715e6492c0a2641868ec1dedaDownloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4Downloading layer: sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5bbHello World: The Python version is 3.5.2 Previous Next Edit me Site last generated: Jul 26, 2017 ">
<meta name="name" content="Singularity Exec">
<meta name="thumbnail" content="http://singularity.lbl.gov/images/logo/logo.svg">
<title>Singularity Exec | 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="Singularity Exec">{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><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 class="active"><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">Singularity Exec</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>
<p>The <code class="highlighter-rouge">exec</code> Singularity sub-command allows you to spawn an arbitrary command within your container image as if it were running directly on the host system. All standard IO, pipes, and file systems are accessible via the command being exec’ed within the container. Note that this exec is different from the Docker exec, as it does not require a container to be “running” before using it.</p>
<h2 id="usage">Usage</h2>
<p>The usage is as follows:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>USAGE: singularity <span class="o">[</span>...] <span class="nb">exec</span> <span class="o">[</span><span class="nb">exec </span>options...] <container path> <<span class="nb">command</span>>
This <span class="nb">command </span>will allow you to execute any program within the given
container image.
EXEC OPTIONS:
-B/--bind <spec> A user-bind path specification. spec has the format
src[:dest[:opts]], where src and dest are outside and
inside paths. If dest is not given, it is <span class="nb">set </span>equal
to src. Mount options <span class="o">(</span><span class="s1">'opts'</span><span class="o">)</span> may be specified as
<span class="s1">'ro'</span> <span class="o">(</span><span class="nb">read</span>-only<span class="o">)</span> or <span class="s1">'rw'</span> <span class="o">(</span><span class="nb">read</span>/write, which is the
default<span class="o">)</span>. This option can be called multiple times.
-c/--contain This option disables the automatic sharing of writable
filesystems on your host <span class="o">(</span>e.g. <span class="nv">$HOME</span> and /tmp<span class="o">)</span>.
-C/--containall Contain not only file systems, but also PID and IPC
-e/--cleanenv Clean environment before running container
-H/--home <spec> A home directory specification. spec can either be a
src path or src:dest pair. src is the <span class="nb">source </span>path
of the home directory outside the container and dest
overrides the home directory within the container
-i/--ipc Run container <span class="k">in </span>a new IPC namespace
-p/--pid Run container <span class="k">in </span>a new PID namespace
--pwd Initial working directory <span class="k">for </span>payload process inside
the container
-S/--scratch <path> Include a scratch directory within the container that
is linked to a temporary dir <span class="o">(</span>use -W to force location<span class="o">)</span>
-u/--user Try to run completely unprivileged <span class="o">(</span>only works on very
new kernels/distros<span class="o">)</span>
-W/--workdir Working directory to be used <span class="k">for</span> /tmp, /var/tmp and
<span class="nv">$HOME</span> <span class="o">(</span><span class="k">if</span> -c/--contain was also used<span class="o">)</span>
-w/--writable By default all Singularity containers are available as
<span class="nb">read </span>only. This option makes the file system accessible
as <span class="nb">read</span>/write.
CONTAINER FORMATS SUPPORTED:
<span class="k">*</span>.img This is the native Singularity image format <span class="k">for </span>all
Singularity versions 2.x.
<span class="k">*</span>.sqsh SquashFS format, note the suffix is required!
<span class="k">*</span>.tar<span class="k">*</span> Tar archives are exploded to a temporary directory and
run within that directory <span class="o">(</span>and cleaned up after<span class="o">)</span>.
Compression suffixes as <span class="s1">'.gz'</span> and <span class="s1">'bz2'</span> are supported.
directory/ Container directories that contain a valid root file
system.
EXAMPLES:
<span class="nv">$ </span>singularity <span class="nb">exec</span> /tmp/Debian.img cat /etc/debian_version
<span class="nv">$ </span>singularity <span class="nb">exec</span> /tmp/Debian.img python ./hello_world.py
<span class="nv">$ </span>cat hello_world.py | singularity <span class="nb">exec</span> /tmp/Debian.img python
<span class="nv">$ </span>sudo singularity <span class="nb">exec</span> --writable /tmp/Debian.img apt-get update
</code></pre>
</div>
<h3 id="examples">Examples</h3>
<h4 id="printing-the-os-release-inside-the-container">Printing the OS release inside the container:</h4>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>singularity <span class="nb">exec </span>container.img cat /etc/os-release
<span class="nv">PRETTY_NAME</span><span class="o">=</span><span class="s2">"Debian GNU/Linux 8 (jessie)"</span>
<span class="nv">NAME</span><span class="o">=</span><span class="s2">"Debian GNU/Linux"</span>
<span class="nv">VERSION_ID</span><span class="o">=</span><span class="s2">"8"</span>
<span class="nv">VERSION</span><span class="o">=</span><span class="s2">"8 (jessie)"</span>
<span class="nv">ID</span><span class="o">=</span>debian
<span class="nv">HOME_URL</span><span class="o">=</span><span class="s2">"http://www.debian.org/"</span>
<span class="nv">SUPPORT_URL</span><span class="o">=</span><span class="s2">"http://www.debian.org/support"</span>
<span class="nv">BUG_REPORT_URL</span><span class="o">=</span><span class="s2">"https://bugs.debian.org/"</span>
<span class="gp">$ </span>
</code></pre>
</div>
<h4 id="special-characters">Special Characters</h4>
<p>And properly passing along special characters to the program within the container.</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>singularity <span class="nb">exec </span>container.img <span class="nb">echo</span> -ne <span class="s2">"hello</span><span class="se">\n</span><span class="s2">world</span><span class="se">\n\n</span><span class="s2">"</span>
hello
world
<span class="gp">$ </span>
</code></pre>
</div>
<p>And a demonstration using pipes:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>cat debian.def | singularity <span class="nb">exec </span>container.img grep <span class="s1">'MirrorURL'</span>
MirrorURL <span class="s2">"http://ftp.us.debian.org/debian/"</span>
<span class="gp">$ </span>
</code></pre>
</div>
<h4 id="a-python-example">A Python example</h4>
<p>Starting with the file <code class="highlighter-rouge">hello.py</code> in the current directory with the contents of:</p>
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="c">#!/usr/bin/python</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="k">print</span><span class="p">(</span><span class="s">"Hello World: The Python version is </span><span class="si">%</span><span class="s">s.</span><span class="si">%</span><span class="s">s.</span><span class="si">%</span><span class="s">s"</span> <span class="o">%</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="p">[:</span><span class="mi">3</span><span class="p">])</span>
</code></pre>
</div>
<p>Because our home directory is automatically bound into the container, and we are running this from our home directory, we can easily execute that script using the Python within the container:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>singularity <span class="nb">exec</span> /tmp/Centos7-ompi.img /usr/bin/python hello.py
Hello World: The Python version is 2.7.5
</code></pre>
</div>
<p>We can also pipe that script through the container and into the Python binary which exists inside the container using the following command:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>cat hello.py | singularity <span class="nb">exec</span> /tmp/Centos7-ompi.img /usr/bin/python
Hello World: The Python version is 2.7.5
</code></pre>
</div>
<p>For demonstration purposes, let’s also try to use the latest Python container which exists in DockerHub to run this script:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>singularity <span class="nb">exec </span>docker://python:latest /usr/local/bin/python hello.py
library/python:latest
Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Downloading layer: sha256:fbd06356349dd9fb6af91f98c398c0c5d05730a9996bbf88ff2f2067d59c70c4
Downloading layer: sha256:644eaeceac9ff6195008c1e20dd693346c35b0b65b9a90b3bcba18ea4bcef071
Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Downloading layer: sha256:766692404ca72f4e31e248eb82f8eca6b2fcc15b22930ec50e3804cc3efe0aba
Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Downloading layer: sha256:6a3d69edbe90ef916e1ecd8d197f056de873ed08bcfd55a1cd0b43588f3dbb9a
Downloading layer: sha256:ff18e19c2db42055e6f34323700737bde3c819b413997cddace2c1b7180d7efd
Downloading layer: sha256:7b9457ec39de00bc70af1c9631b9ae6ede5a3ab715e6492c0a2641868ec1deda
Downloading layer: sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Downloading layer: sha256:6a5a5368e0c2d3e5909184fa28ddfd56072e7ff3ee9a945876f7eee5896ef5bb
Hello World: The Python version is 3.5.2
</code></pre>
</div>
<!-- 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/docs-exec.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>