Skip to content

Commit 37ed9a4

Browse files
committed
updating quickstart to be more specific about permissions
1 parent 2a2147e commit 37ed9a4

1 file changed

Lines changed: 74 additions & 23 deletions

File tree

pages/docs/overview/start.md

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ title: Quick Start
33
sidebar: main_sidebar
44
permalink: quickstart
55
folder: docs
6-
toc: false
6+
toc: true
77
---
88

99
## Installation Quick Start
10+
Note that this quickstart is intended for using Singularity on your personal workstation, where you have installed Singularity and have sudo. If you only have access to Singularity on a shared cluster resource, you will be able to go through all parts of this tutorial that do not require writing to an image. First, if you are on your local machine, let's install Singularity.
1011

1112
```bash
1213
git clone {{ site.repo }}.git
@@ -17,7 +18,10 @@ make
1718
sudo make install
1819
```
1920

21+
Installing Singularity as a user, or without sudo, will not produce software that works properly. If you want Singularity on your shared cluster resource, you should ask an administrator to install it for you!
22+
2023
## Command Quick Start
24+
This first section of commands can be done on a shared resource, or your personal computer. You don't need sudo to create, import, or shell into containers.
2125

2226
### Make a container
2327

@@ -40,8 +44,38 @@ Importing: /home/vanessa/.singularity/docker/sha256:785fe1d06b2d42874d3e18fb0747
4044
Importing: /home/vanessa/.singularity/docker/sha256:a90ac515821d5b70fe202c201485396ba95305348f9f7f52813e2873d3c72eee.tar.gz
4145
```
4246

47+
### Pull a container
48+
Another easy way to obtain and use a container is to pull it directly. Here we can pull centos directly from Docker Hub, or pull an image from Singularity Hub.
49+
50+
```
51+
singularity pull docker://centos:latest
52+
Initializing Singularity image subsystem
53+
Opening image file: centos-latest.img
54+
Creating 336MiB image
55+
Binding image to loop
56+
Creating file system within image
57+
Image is done: centos-latest.img
58+
Docker image path: index.docker.io/library/centos:latest
59+
Cache folder set to /home/vanessa/.singularity/docker
60+
[1/1] |===================================| 100.0%
61+
Importing: base Singularity environment
62+
Importing: /home/vanessa/.singularity/docker/sha256:d5e46245fe40c2d1ab72bfe328de28549b605b2587ab2fa8715f54e3e2de9c5d.tar.gz
63+
Importing: /home/vanessa/.singularity/metadata/sha256:6b8bbe197a20c88d065c265cf6f6f8b4e3695f104d1f47f01a1298b3566f27fe.tar.gz
64+
Done. Container is at: centos-latest.img
65+
```
66+
67+
Did you notice anything interesting about the output to the terminal? If you noticed that the above output for "pull" is similar to the output of "create" and "import" combined, you nailed it on the head! In the context of docker, running the `pull` command is an easy shortcut to create and import docker layers to an image. Whereas Docker creates and imports layers into an image on pull, when we pull (or run, or shell) an image from Singularity Hub, the entire image is downloaded. This is one of the main differences between Docker and Singularity:
68+
69+
```
70+
singularity run shub://vsoch/hello-world
71+
Progress |===================================| 100.0%
72+
RaawwWWWWWRRRR!!
73+
$ ls vsoch*
74+
vsoch-hello-world-master.img
75+
```
4376

4477
### Shell into container
78+
Now let's go back to the `centos7.img` we created, and shell inside.
4579

4680
```bash
4781
singularity shell centos7.img
@@ -61,45 +95,59 @@ Want to keep the container's environment contained, meaning no sharing of host e
6195
singularity shell --contain centos7.img
6296
```
6397

64-
### Writing in the container
65-
By default, containers run in read only. While we discourage making tweaks on the fly to containers (you should properly define all edits to the container in a boostrap specification file, shown later) you can add `--writable` to any command to write inside the container. Let's make a directory. This command must be done with sudo.
66-
67-
```bash
68-
sudo singularity shell --writable centos7.img
69-
Singularity centos7.img:/root> mkdir /data
70-
Singularity centos7.img:/root> touch /data/noodles.txt
71-
exit
72-
```
73-
7498
### Executing Commands
75-
Singularity `exec` will send a custom command for the container to run, anything that you like! Unlike docker exec, the container doesn't have to be actively running. So, to list the `/data` folder we just bound, we could do the following:
99+
Singularity `exec` will send a custom command for the container to run, anything that you like! Unlike docker exec, the container doesn't have to be actively running. So, to list the root of the image (`/`), we could do the following:
76100

77101
```bash
78-
# Did the directory persist?
79-
singularity exec centos7.img ls /data
80-
noodles.txt
102+
singularity exec centos7.img ls /
103+
anaconda-post.log etc lib64 mnt root singularity tmp
104+
bin home lost+found opt run srv usr
105+
dev lib media proc sbin sys var
81106
```
82107

83-
84108
### Working with Files
85109

86110
Files on the host can be reachable from within the container
87111

88112
```bash
89-
echo "Hello World" > /home/vanessa/Desktop/hello-kitty.txt
90-
singularity exec centos7.img cat /home/vanessa/Desktop/hello-kitty.txt
113+
echo "Hello World" > $HOME/hello-kitty.txt
114+
singularity exec centos7.img cat $HOME/hello-kitty.txt
91115
Hello World
92116
```
93117

94-
By default, most configurations will mount `/tmp` and the home directories by default. On a research cluster, you probably want to access locations with big datasets, and then write results too. For this, you will want to bind a folder to the container. Here, we are binding my Desktop to the data folder, and listing the contents to show it worked. We use the command `-B` or `--bind` to do this.
118+
By default, most configurations will mount `/tmp` and the home directories by default. On a research cluster, you probably want to access locations with big datasets, and then write results too. For this, you will want to bind a folder to the container. Here, we are binding my Desktop to `/opt` in the image, and listing the contents to show it worked. We use the command `-B` or `--bind` to do this.
95119

96120
```bash
97-
$ singularity exec --bind /home/vanessa/Desktop:/data centos7.img ls /data
121+
$ singularity exec --bind /home/vanessa/Desktop:/opt centos7.img ls /opt
98122
centos7.img researchapps-matlab-sherlock-master.img
99123
hello-kitty.txt singularity-recipe-demo.mp4
100124
party_dinosaur.gif
101125
````
102126

127+
## Commands needing root
128+
The next set of actions, namely anything with `--writable` or bootstrap, do require you to use sudo. If you have been working on your shared resource, you will need to move to your personal laptop (and install Singularity if you haven't yet) before trying these out.
129+
130+
131+
### Writing in the container
132+
By default, containers run in read only. While we discourage making tweaks on the fly to containers (you should properly define all edits to the container in a boostrap specification file, shown later) you can add `--writable` to any command to write inside the container. Assuming we have our `centos7.img` on our local resource with sudo, let's make a directory.
133+
134+
135+
```bash
136+
sudo singularity shell --writable centos7.img
137+
Singularity centos7.img:/root> mkdir /data
138+
Singularity centos7.img:/root> touch /data/noodles.txt
139+
exit
140+
```
141+
142+
Did we make noodles? Is the file still there?
143+
144+
```bash
145+
singularity exec centos7.img ls /data
146+
noodles.txt
147+
```
148+
149+
We(ideally) would have done this action with bootstrap, discussed next.
150+
103151
### Bootstrap Recipes
104152
For a reproducible container, the recommended practice is to build by way of a bootstrap file. This also makes it easy to add files, environment variables, and install custom software, and still start from your bootstrap of source (e.g., Docker). Here is what a basic bootstrap file looks like for Singularity 2.3:
105153

@@ -118,7 +166,8 @@ exec echo "The runscript is the containers default runtime command!"
118166
119167
120168
%environment
121-
VARIABLE MEATBALLVALUE
169+
VARIABLE=MEATBALLVALUE
170+
export VARIABLE
122171
123172
%labels
124173
AUTHOR vsochat@stanford.edu
@@ -130,10 +179,12 @@ mkdir /data
130179
echo "The post section is where you can install, and configure your container."
131180
```
132181

133-
The above bootstrap definition can then be run with singularity. Assuming that the definition was saved as `ubuntu.def` and an image file `ubuntu.img` exists, the following will build the container.
182+
The above bootstrap definition can then be run with singularity. Assuming that the definition was saved as `Singularity` and an image file `ubuntu.img` exists, the following will build the container.
134183

135184
```bash
136-
singularity bootstrap ubuntu.img ubuntu.def
185+
sudo singularity bootstrap ubuntu.img Singularity
137186
```
138187

188+
How might you go through this entire process without having singularity installed locally, or without leaving your cluster? You can build images using <a href="https://github.com/singularityhub/singularityhub.github.io/wiki" target="_blank">singularity hub.</a>
189+
139190
{% include links.html %}

0 commit comments

Comments
 (0)