generated from jhudsl/OTTR_Template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path04-using-volumes.qmd
More file actions
135 lines (91 loc) · 7.8 KB
/
04-using-volumes.qmd
File metadata and controls
135 lines (91 loc) · 7.8 KB
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
# Using Volumes
```{r, out.width = "100%", fig.alt = "This chapter will demonstrate how to: Recognize the purpose of volumes Mount a volume to a Docker container", echo = FALSE}
ottrpal::include_slide("https://docs.google.com/presentation/d/1T5Lfei2UVou9b0qaUCrWXmkcIwAao-UcN4pHMPEE4CY/edit#slide=id.g2effc5b673e_0_842")
```
In the last chapter we saw that we were using a container but were unable to access files we needed. We were trying to call the `run_analysis.sh` script but the isolation of containers that makes them useful also means that we didn't have this script on our container.
So how do we get files we need onto a container we are using?
There are a few options:
- We could run our container and within that we could download the files we need from online! For example we could `git clone` files from a repository or otherwise `wget` or `curl` files that are stored online somewhere.
- We could `COPY` a file on to the docker image when we are building it (more on this next chapter). But we want to be careful with this strategy for two reasons:
- We don't want our image to be too big. So, this strategy can be fine if the file is small and something we know will always be needed for any use of the container.
- We DEFINITELY need to avoid ever having protected data on images that are shared. NEVER put protected data on images that we are sharing -- more on this later too.
- Lastly we can add a `volume` of files that are local to our computer. We'll dive into this strategy in this chapter. This will probably be the most common way you'll use to get access to files on your container.
What is a volume? A volume is a folder, likely from your computer, that can be accessed by your container.
```{r, out.width = "100%", fig.alt = "In our growing diagram we can now see that attached to a container which is An environment we can run stuff in we now have a volume which is a Folder that can be accessed by the container", echo = FALSE}
ottrpal::include_slide("https://docs.google.com/presentation/d/1T5Lfei2UVou9b0qaUCrWXmkcIwAao-UcN4pHMPEE4CY/edit#slide=id.g30a4ed49e59_0_1097")
```
I think of volumes like portals:
<iframe src="https://giphy.com/embed/4sDxn0FxPG2SN2iF9E" width="480" height="269" style="" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/tide-seriously-disappointed-judging-you-4sDxn0FxPG2SN2iF9E">via GIPHY</a></p>
The portal/volume can be opened when you `RUN` the container. And when you stop and delete the container the portal is no longer there. But its a way that your container can access and modify files on your computer for the time being.
```{r panel-setup, include = FALSE}
xaringanExtra::use_panelset()
xaringanExtra::style_panelset_tabs(font_family = "inherit")
```
## Activity Instructions {.panelset}
### Docker
Our container is separate from our computer so if we want to use a file from our computer we have to attach it using a "volume".
##### Step 1: Let’s add our containers-for-scientists-sandbox files
Let's point a volume to our workshop files so we have them on our container.
We can specify a particular file path on our computer or give it `$PWD`. Then optionally we can give a `:` and a file path where we'd like it to be stored on the container. Otherwise it will be stored at the absolute top of the container. Note that `$PWD` is a special environment variable that stores the absolute path of the current working directory. You will need to be in the `containers-for-scientists-sandbox-main` for this to work.
```{r, out.width = "100%", fig.alt = "This diagram shows a docker run command where a volume is specified. -v is used to specify the volume which has two pieces to the option. First is the Folder on your computer with files you want accessible then a colon is placed and on the other side of this colon a file path that indicates Where these files should show up on your container After this option the image name is given as is typical for docker run.", echo = FALSE}
ottrpal::include_slide("https://docs.google.com/presentation/d/1T5Lfei2UVou9b0qaUCrWXmkcIwAao-UcN4pHMPEE4CY/edit#slide=id.g30a4ed49e59_0_1128")
```
<input type="checkbox"> Now we can run:
```
docker run -v $PWD:/home cansav09/practice-image:1
```
If you have a windows machine you may have to run this variant instead. This version has a different `${}` around the `pwd` part.
```
docker run -v ${pwd}:/home cansav09/practice-image:1
```
In Docker desktop you can specify a portal like this:
```{r, out.width = "100%", echo = FALSE}
ottrpal::include_slide("https://docs.google.com/presentation/d/1T5Lfei2UVou9b0qaUCrWXmkcIwAao-UcN4pHMPEE4CY/edit#slide=id.g30a4ed49e59_0_1116")
```
#### Step 2: Retry calling the script
<input type="checkbox"> Now we can run the following command but we will have to run `docker ps` and get the container ID we need to put here.
```
docker exec -it <REPLACE_WITH_CONTAINER_ID> bash /home/run_analysis.sh
```
or in the exec tab of the container in Docker desktop app, run
```
bash /home/run_analysis.sh
```
```{r, out.width = "100%", fig.alt = "Now we have a new error. Error in loadnamespace(x) there is no package called rmarkdown. What do we think this means?", echo = FALSE}
ottrpal::include_slide("https://docs.google.com/presentation/d/1T5Lfei2UVou9b0qaUCrWXmkcIwAao-UcN4pHMPEE4CY/edit#slide=id.g30a4ed49e59_0_1152")
```
Now we have a new error! What does this mean?
**Question: Does our container have all of the same software that our computer has?**
```{r, out.width = "100%", fig.alt = "Does our container have all of the same software that our computer has?", echo = FALSE}
ottrpal::include_slide("https://docs.google.com/presentation/d/1T5Lfei2UVou9b0qaUCrWXmkcIwAao-UcN4pHMPEE4CY/edit#slide=id.g30a4ed49e59_0_1160")
```
### Podman
Our container is separate from our computer so if we want to use a file we have to attach it using a "volume".
##### Step 1: Let’s add our containers-for-scientists-sandbox files
Let's point a volume to our workshop files so we have them on our container.
We can specify a particular file path on our computer or give it `$PWD` Then optionally we can give a `:` and a file path we'd like this to be stored on on the container. Otherwise it will be stored at the absolute top of the container.
<input type="checkbox"> Now we can run:
```
podman run -v $pwd:/home cansav09/practice-image:1
```
If you have a windows machine you may have to run this variant instead. This version has a different `${}` around the `pwd` part.
```
podman run -v ${pwd}:/home cansav09/practice-image:1
```
```{r, out.width = "100%", fig.alt = "This diagram shows a podman run command where a volume is specified. -v is used to specify the volume which has two pieces to the option. First is the Folder on your computer with files you want accessible then a colon is placed and on the other side of this colon a file path that indicates Where these files should show up on your container. After this option the image name is given as is typical for docker run.", echo = FALSE}
ottrpal::include_slide("https://docs.google.com/presentation/d/1T5Lfei2UVou9b0qaUCrWXmkcIwAao-UcN4pHMPEE4CY/edit#slide=id.g30a80783034_1_15")
```
#### Step 2: Retry calling the script
<input type="checkbox"> Now we can run the following command but we will have to run `podman ps` and get the container ID we need to put here.
```
podman exec -it <REPLACE_WITH_CONTAINER_ID> bash /home/run_analysis.sh
```
Now we have a new error:
```
Error in loadNamespace(x): There is no package called 'rmarkdown'
```
What does this mean?
**Question: Does our container have all of the same software that our computer has?**
```{r, out.width = "100%", fig.alt = "Does our container have all of the same software that our computer has?", echo = FALSE}
ottrpal::include_slide("https://docs.google.com/presentation/d/1T5Lfei2UVou9b0qaUCrWXmkcIwAao-UcN4pHMPEE4CY/edit#slide=id.g30a4ed49e59_0_1160")
```