You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/docker/index.md
+68-16Lines changed: 68 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,16 +13,34 @@ redirect: false
13
13
14
14
Docker is a way to share pre-built, pre-configured, and platform-independent sets of programs and files. The PhyloDocker image described below comes pre-configured with RevBayes, the TensorPhylo library, and other useful software.
15
15
16
-
As a user, you download and a build a Docker image. Once built, you can create a Docker container from that image. Each Docker image lives on your computer and uses its resources for work. In this way, you can think of Docker as a program that runs a miniature "virtual" computer through your actual computer. A container built from PhyloDocker can be used to run RevBayes, just like you would through the terminal, but without needing to install and configure RevBayes yourself. For example:
16
+
As a user, you download and a build a Docker image. Once built, you can create a Docker container from that image. Each Docker image lives on your computer and uses its resources for work. In this way, you can think of Docker as a program that runs a miniature "virtual" computer through your actual computer. A container built from PhyloDocker can be used to run RevBayes, just like you would through the terminal, but without needing to install and configure RevBayes yourself.
17
+
18
+
On the development side, a **Dockerfile** (a list of commands for building and configuring programs/files) is used to build an **image**, which can then be shared with others. On the user side, the image can be downloaded and run to create a **container**. Inside the container, you have access to all of the programs contained in the image, as well as any files you **mount** to the container when you run the image. It works a bit like a virtual machine, except it runs on top of the host operating system. A Docker image containing RevBayes, TensorPhylo, Python, R, Julia, and several other programs can be found on [Docker Hub](https://hub.docker.com/r/sswiston/phylo_docker).
19
+
20
+
This tutorial explains how to install Docker on your computer, how to obtain a RevBayes Docker image, and how to use the image to run scripts on your computer or a computing cluster. This will require a basic familiarity with command line (navigating directories and entering basic commands), but does not require much programming.
21
+
22
+
{% subsection Basic example %}
23
+
24
+
This tutorial includes a test script called `test.Rev` so that you can assess whether the RevBayes Docker container is functioning properly after being installed. The test script can be found in the `Data files and scripts` box in the left sidebar of the tutorial page. Somewhere on your computer, you should create a directory (folder) for this tutorial, download the test script, and put the test script inside the directory. You can put this directory anywhere you want on your computer, but you will need to know the filepath to the directory in order to access it from the Docker container. Here, we assume the working directory will be `/Users/mlandis/projects/docker_test`.
25
+
26
+
Create and run a new Docker container, and start with an interactive shell session:
17
27
18
28
```
19
29
~ $ ### from terminal on my Mac laptop (host)
20
-
~ $ docker run --name phylodocker_demo --volume /Users/mlandis/projects/docker_test:/docker_test -it sswiston/phylo_docker:slim_amd64
You should now be at the shell prompt within the Docker container! Try running the test script that is bundled with PhyloDocker.
21
38
39
+
```
22
40
~ # ### from terminal inside Docker container
23
41
~ # cd docker_test/
24
42
/docker_test # ls
25
-
history.txt test.Rev
43
+
test.Rev
26
44
/docker_test # rb test.Rev
27
45
28
46
RevBayes version (1.2.2)
@@ -44,25 +62,57 @@ Congrats! RevBayes is working!
44
62
/docker_test # ls
45
63
new_file.txt test.Rev
46
64
/docker_test # exit
65
+
```
66
+
67
+
You have closed the Docker session and returned to your computer (the host machine). Make sure the file is there. After that, find your old Docker container, resume the session, tell the world hello, then exit when done:
47
68
48
-
~ $ ### back on my laptop (host)
69
+
```
70
+
~ $ ### from terminal on laptop (host)
71
+
~ $ # show new files are present
49
72
~ $ ls /Users/mlandis/projects/docker_test
50
73
new_file.txt test.Rev
51
74
52
-
~ $ ### reconnect to Docker container
75
+
~ $ # show active Docker containers
76
+
~ docker ps -a
77
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
78
+
fb19b94184ac sswiston/phylo_docker:slim_amd64 "/bin/sh" 5 minutes ago Exited (0) 4 minutes ago phylodocker_demo
79
+
80
+
~ $ # resume active Docker container using start
53
81
~ $ docker start -ai phylodocker_demo
54
-
~ #
55
-
```
56
82
57
-
On the development side, a **Dockerfile** (a list of commands for building and configuring programs/files) is used to build an **image**, which can then be shared with others. On the user side, the image can be downloaded and run to create a **container**. Inside the container, you have access to all of the programs contained in the image, as well as any files you **mount** to the container when you run the image. It works a bit like a virtual machine, except it runs on top of the host operating system. A Docker image containing RevBayes, TensorPhylo, Python, R, Julia, and several other programs can be found on [Docker Hub](https://hub.docker.com/r/sswiston/phylo_docker).
83
+
--> Enters the Docker container <--
58
84
59
-
This tutorial explains how to install Docker on your computer, how to obtain a RevBayes Docker image, and how to use the image to run scripts on your computer or a computing cluster. This will require a basic familiarity with command line (navigating directories and entering basic commands), but does not require much programming.
85
+
~ # ### back in the Docker container
86
+
~ # echo Hello, world!
87
+
Hello, world!
88
+
~ # exit
89
+
```
60
90
61
-
{% section Setting up the tutorial %}
91
+
Delete your Docker container when it's done. Note, files saved to the mounted directory `/docker_test` also exist on your host computer's filesystem, so they will not be deleted:
62
92
63
-
{% subsection Downloading a test script %}
93
+
```
94
+
~ $ ### back on my laptop again (host)
95
+
~ $ # remove old Docker container once done with it
96
+
~ $ docker rm phylodocker_demo
97
+
phylodocker_demo
98
+
~ $ # files continue to exist
99
+
~ $ ls /Users/mlandis/projects/docker_test
100
+
new_file.txt test.Rev
101
+
```
102
+
{% subsection Useful Docker commands %}
103
+
104
+
Docker supports a large number of commands to manage images and containers (see [Docker CLI Documentation](https://docs.docker.com/reference/cli/docker/)). These six commands will cover the needs for most RevBayes users:
64
105
65
-
This tutorial includes a test script called `test.Rev` so that you can assess whether the RevBayes Docker container is functioning properly after being installed. The test script can be found in the `Data files and scripts` box in the left sidebar of the tutorial page. Somewhere on your computer, you should create a directory (folder) for this tutorial, download the test script, and put the test script inside the directory. You can put this directory anywhere you want on your computer, but you will need to know the filepath to the directory in order to access it from the Docker container.
@@ -83,7 +133,7 @@ Example view of containers in Docker Desktop.
83
133
84
134
This is a reference to {% ref example %}
85
135
86
-
{% subsection Downloading the image %}
136
+
{% subsection Downloading the Docker image %}
87
137
88
138
A Docker image containing RevBayes, TensorPhylo, Python, R, and other dependencies can be found at [hub.docker.com/r/sswiston/phylo_docker](https://hub.docker.com/r/sswiston/phylo_docker). The easiest way to obtain this image is with a `docker pull` command.
89
139
@@ -133,10 +183,10 @@ You can also run the RevBayes Docker image directly from command line. This will
133
183
134
184
```
135
185
# For Intel/AMD computers
136
-
docker run --name [my_container] --volume [local_directory]:[container_directory] -it sswiston/phylo_docker:slim_amd64
186
+
docker run --name [my_container] --volume [local_directory]:[container_directory] -it sswiston/phylo_docker:slim_amd64 /bin/sh
137
187
138
188
# For Apple Silicon (M1, M2, etc.) computers
139
-
docker run --name [my_container] --volume [local_directory]:[container_directory] -it sswiston/phylo_docker:slim_arm64
189
+
docker run --name [my_container] --volume [local_directory]:[container_directory] -it sswiston/phylo_docker:slim_arm64 /bin/sh
140
190
```
141
191
142
192
Some parts of this command are directly analogous to the optional settings from the RevBayes GUI.
@@ -151,6 +201,8 @@ You can also run the RevBayes Docker image directly from command line. This will
151
201
152
202
- `sswiston/phylo_docker:slim_amd64` or `sswiston/phylo_docker:slim_arm64` (hardware-dependent, see above) is the name of the Docker image you want to use.
153
203
204
+
- `/bin/sh` tells the Docker container to open a new terminal (shell) session when it starts.
205
+
154
206
Congrats, you are inside the Docker container! You should be able to access all of the programs and files in the container, and also the directory you mounted from your host machine.
155
207
156
208
4. Navigate to the location of your test script with `cd [filepath]`, using the filepath that you mounted your directory to in Step 3.
@@ -190,7 +242,7 @@ You can use the Docker Desktop GUI to run the RevBayes Docker image (but see cav
190
242
191
243
9. Another tab on the lefthand side of the screen should be called `containers`. Clicking this option should bring you to a screen showing all of the containers you currently have running.
192
244
193
-
10. There are two ways to access the container as it is running. The first way is to click on the running container inside the Containers panel, and then click on the Exec tab from the list of tabs at the top of the container menu. The second way is to find the running container inside the Containers panel, and then click on the icon with three vertical dots to the right of the container name. This will open a menu of options. Click on the "Open in terminal" menu item. Clicking this option will take you to the Exec tab, as in the first option. Congrats, you are inside the Docker container! You should be able to access all of the programs and files in the container, and also the directory you mounted from your host machine.
245
+
10. There are two ways to access the container as it is running. The first way is to click on the running container inside the Containers panel, and then click on the `Exec` tab from the list of tabs at the top of the container menu. The second way is to find the running container inside the Containers panel, and then click on the icon with three vertical dots to the right of the container name. This will open a menu of options. Click on the "Open in terminal" menu item. Clicking this option will take you to the `Exec` tab, as in the first option. Within the `Exec` tab, there is a blue link that says *"Open in external terminal"*, which allows you to use your own terminal program to control the Docker session. Congrats, you are inside the Docker container! You should be able to access all of the programs and files in the container, and also the directory you mounted from your host machine.
194
246
195
247
11. Navigate to the location of your test script with `cd [filepath]`, using the filepath that you mounted your directory to in Step 7.
0 commit comments