Skip to content

Commit 9b56800

Browse files
GodloveDvsoch
authored andcommitted
adding instance commands to sidebar group (#130)
* adding instance commands to sidebar group * added some links from instance page to commands * few changes in intro
1 parent 40ccd78 commit 9b56800

5 files changed

Lines changed: 189 additions & 7 deletions

File tree

_data/sidebars/user_docs.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ entries:
100100
output: web, pdf
101101

102102

103-
- title: Image Commands
103+
- title: Image Command Group
104104
output: web, pdf
105105
folderitems:
106106

@@ -120,11 +120,26 @@ entries:
120120
url: /docs-create
121121
output: web, pdf
122122

123+
- title: Instance Command Group
124+
output: web, pdf
125+
folderitems:
126+
127+
- title: instance.start
128+
url: /docs-instance-start
129+
output: web, pdf
130+
131+
- title: instance.list
132+
url: /docs-instance-list
133+
output: web, pdf
134+
135+
- title: instance.stop
136+
url: /docs-instance-stop
137+
output: web, pdf
123138

124139
- title: Deprecated
125140
output: web, pdf
126-
127141
folderitems:
142+
128143
- title: bootstrap
129144
url: /docs-bootstrap
130145
output: web, pdf
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: instance.list
3+
sidebar: user_docs
4+
permalink: /docs-instance-list
5+
folder: docs
6+
toc: false
7+
---
8+
9+
New in Singularity version 2.4 you can use the `instance` command group to run instances of containers in the background. This is useful for running services like databases and web servers. The `instance.list` command lets you keep track of the named instances running in the background.
10+
11+
{% include toc.html %}
12+
13+
## Overview
14+
After initiating one or more named instances to run in the background with the `instance.start` command you can list them with the `instance.list` command.
15+
16+
## Examples
17+
These examples use a container from Singularity Hub, but you can use local containers or containers from Docker Hub as well. For a more detailed look at `instance` usage see [Running Instances](docs-instances).
18+
19+
### Start a few named instances from containers on Singularity Hub
20+
```
21+
$ singularity instance.start shub://GodloveD/lolcow cow1
22+
$ singularity instance.start shub://GodloveD/lolcow cow2
23+
$ singularity instance.start shub://vsoch/hello-world hiya
24+
```
25+
### List running instances
26+
```
27+
$ singularity instance.list
28+
DAEMON NAME PID CONTAINER IMAGE
29+
cow1 20522 /home/ubuntu/GodloveD-lolcow-master.img
30+
cow2 20558 /home/ubuntu/GodloveD-lolcow-master.img
31+
hiya 20595 /home/ubuntu/vsoch-hello-world-master.img
32+
```
33+
34+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: instance.start
3+
sidebar: user_docs
4+
permalink: /docs-instance-start
5+
folder: docs
6+
toc: false
7+
---
8+
9+
New in Singularity version 2.4 you can use the `instance` command group to run instances of containers in the background. This is useful for running services like databases and web servers. The `instance.start` command lets you initiate a named instance in the background.
10+
11+
{% include toc.html %}
12+
13+
## Overview
14+
To initiate a named instance of a container, you must call the `instance.start` command with 2 arguments: the name of the container that you want to start and a unique name for an instance of that container. Once the new instance is running, you can join the container's namespace using a URI style syntax like so:
15+
16+
```
17+
$ singularity shell instance://<instance_name>
18+
```
19+
20+
You can specify options such as bind mounts, overlays, or custom namespaces when you initiate a new instance of a container with `instance.start`. These options will persist as long as the container runs.
21+
22+
For a complete list of options see the output of:
23+
24+
```
25+
singularity help instance.start
26+
```
27+
28+
## Examples
29+
These examples use a container from Singularity Hub, but you can use local containers or containers from Docker Hub as well. For a more detailed look at `instance` usage see [Running Instances](docs-instances).
30+
31+
### Start an instance called cow1 from a container on Singularity Hub
32+
```
33+
$ singularity instance.start shub://GodloveD/lolcow cow1
34+
```
35+
### Start an interactive shell within the instance that you just started
36+
```
37+
$ singularity shell instance://cow1
38+
Singularity GodloveD-lolcow-master.img:~> ps -ef
39+
UID PID PPID C STIME TTY TIME CMD
40+
ubuntu 1 0 0 20:03 ? 00:00:00 singularity-instance: ubuntu [cow1]
41+
ubuntu 3 0 0 20:04 pts/0 00:00:00 /bin/bash --norc
42+
ubuntu 4 3 0 20:04 pts/0 00:00:00 ps -ef
43+
Singularity GodloveD-lolcow-master.img:~> exit
44+
```
45+
46+
### Execute the runscript within the instance
47+
```
48+
$ singularity run instance://cow1
49+
_________________________________________
50+
/ Clothes make the man. Naked people have \
51+
| little or no influence on society. |
52+
| |
53+
\ -- Mark Twain /
54+
-----------------------------------------
55+
\ ^__^
56+
\ (oo)\_______
57+
(__)\ )\/\
58+
||----w |
59+
|| ||
60+
```
61+
62+
### Run a command within a running instance.
63+
```
64+
$ singularity exec instance://cow1 cowsay "I like blending into the background"
65+
_____________________________________
66+
< I like blending into the background >
67+
-------------------------------------
68+
\ ^__^
69+
\ (oo)\_______
70+
(__)\ )\/\
71+
||----w |
72+
|| ||
73+
```
74+
75+
76+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: instance.stop
3+
sidebar: user_docs
4+
permalink: /docs-instance-stop
5+
folder: docs
6+
toc: false
7+
---
8+
9+
New in Singularity version 2.4 you can use the `instance` command group to run instances of containers in the background. This is useful for running services like databases and web servers. The `instance.stop` command lets you stop instances once you are finished using them
10+
11+
{% include toc.html %}
12+
13+
## Overview
14+
After initiating one or more named instances to run in the background with the `instance.start` command you can stop them with the `instance.stop` command.
15+
16+
## Examples
17+
These examples use a container from Singularity Hub, but you can use local containers or containers from Docker Hub as well. For a more detailed look at `instance` usage see [Running Instances](docs-instances).
18+
19+
### Start a few named instances from containers on Singularity Hub
20+
```
21+
$ singularity instance.start shub://GodloveD/lolcow cow1
22+
$ singularity instance.start shub://GodloveD/lolcow cow2
23+
$ singularity instance.start shub://vsoch/hello-world hiya
24+
```
25+
### Stop a single instance
26+
```
27+
$ singularity instance.stop cow1
28+
Stopping cow1 instance of /home/ubuntu/GodloveD-lolcow-master.img (PID=20522)
29+
```
30+
31+
### Stop all running instances
32+
```
33+
$ singularity instance.stop \*
34+
Stopping cow2 instance of /home/ubuntu/GodloveD-lolcow-master.img (PID=20558)
35+
Stopping hiya instance of /home/ubuntu/vsoch-hello-world-master.img (PID=20595)
36+
```
37+
38+

pages/docs/user-docs/docs-instances.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ service nginx start
2020

2121
With older versions of Singularity, if you were to do something like this, from inside the container you would happily see the service start, and the web server running! But then if you were to log out of the container what would happen?
2222

23-
Ghost process within unreachable namespaces! It's like the walking dead!
23+
Orphan process within unreachable namespaces!
2424

25-
You would lose control of the process. It would still be running, but you couldn't easily kill or interface with it. This is a called a ghost process, and it means that for running persistent services, Singularity was a non-starter.
25+
You would lose control of the process. It would still be running, but you couldn't easily kill or interface with it. This is a called a orphan process. Singularity versions less than 2.4 were not designed to handle running services properly.
2626

2727
## Container Instances in Singularity
28-
With Singularity 2.4 and the addition of container instances, the ability to cleanly, reliably, and safely run services in a container is here. First, let's put the commands of how to start our service into a script. Let's call it a `startscript`. And we can imagine this fitting into a build definition file like this:
28+
With Singularity 2.4 and the addition of container instances, the ability to cleanly, reliably, and safely run services in a container is here. First, let's put some commands that we want our instance to execute into a script. Let's call it a `startscript`. This fits into a definition file like so:
2929

3030
```
3131
%startscript
3232
3333
service nginx start
3434
```
3535

36-
Now let's say we build a container with that startscript into an image called `nginx.img` and we want to run an nginx service. All we need to do is start the instance and the startscript will get run inside the container automatically:
36+
Now let's say we build a container with that startscript into an image called `nginx.img` and we want to run an nginx service. All we need to do is start the instance with the [`instance.start`](docs-instance-start) command, and the startscript will run inside the container automatically:
3737

3838
```
3939
[command] [image] [name of instance]
4040
$ singularity instance.start nginx.img web
4141
```
4242

43-
When we run that command, Singularity creates an isolated environment for the container instances' processes/services to live inside. We can confirm that this command started an instance by running the following command:
43+
When we run that command, Singularity creates an isolated environment for the container instances' processes/services to live inside. We can confirm that this command started an instance by running the [`instance.list`](docs-instance-list) command like so:
4444

4545
```
4646
$ singularity instance.list
@@ -90,6 +90,20 @@ $ singularity exec instance://web1 ps -ef
9090

9191
When using `run` with an instance URI, the `runscript` will be executed inside of the instance. Similarly with `exec`, it will execute the given command in the instance.
9292

93+
When you are finished with your instance you can clean it up with the [`instance.stop`](docs-instance-stop) command like so:
94+
95+
```
96+
$ singularity instance.stop web1
97+
```
98+
99+
If you have multiple instances running and you want to stop all of them, you can do so with a wildcard:
100+
101+
```
102+
$ singularity instance.stop \*
103+
```
104+
105+
Note that you must escape the wildcard with a backslash like this `\*` to pass it properly.
106+
93107
## Putting it all together
94108

95109
In this section, we will demonstrate an example of packaging a service into a container and running it. The service we will be packaging is an API server that converts a web page into a PDF, and can be found [here](https://github.com/alvarcarto/url-to-pdf-api). The final example can be found [here on GitHub](https://github.com/bauerm97/instance-example), and [here on SingularityHub](https://singularity-hub.org/collections/bauerm97/instance-example/). If you wish to just download the final image directly from Singularity Hub, simply run `singularity pull shub://bauerm97/instance-example`.
@@ -240,6 +254,11 @@ $ ls out/
240254
google.pdf
241255
```
242256

257+
When you are finished, use the `instance.stop` command to close all running instances.
258+
259+
```
260+
$ singularity instance.stop \*
261+
```
243262

244263
## Important Notes
245264

0 commit comments

Comments
 (0)