In class these exercises will be run onto the classroom iMacs.
However, as best as I can I’ll provide Windows hints and instructions when possible, but a basic understanding of line-command under Windows would be more than useful for that (e.g. know what is DOS for example. See APPENDIX C.)
Be familiar with Docker or follow earlier workshops: “Docker - Beginner Biologist” workshops 1,2,3.
Docker will be used from a line-command terminal: Terminal
on a Macintosh in the classroom. A rudimentary knowledge of bash
command-line is necessary.
If you are a Windows user: PowerShell
can be used as a Terminal. However, setting Docker to run on Windows is more involved (not covered in class.)
Docker username: downloads will require a (free) username, therefore registration is necessary in order to follow the tutorial. Go to https://hub.docker.com and use the button “Sign up for Docker Hub” to register.
Tutorials will be held in the Biochemistry classroom 201, and Docker has already be installed.
Instruction for installation can be found on the install link1 of the Docker web site.
Note HTML Version only:
If you are following this document in HTML format the code is shown with a colored background:
White background: standard output of programs.
To get started we need to open a text terminal as detailed below. In class we’ll use a Macintosh.
Do one of the following:.
If you are on a Macintosh:
Terminal
icon in the /Applications/Utilities
directory. Then double-click on the icon and Terminal
will open.Terminal
and press return. Terminal
will open.If you are on a PC:
Power Shell
e.g. using Windows search or Cortana. This will open a suitable text-based terminal.(Note: Windows cmd
does not offer the appropriate commands.)
This ensures that Docker is properly installed. The exact running version itself is not very important.
At the $
or >
prompt within the window of Terminal
or PowerShell
type docker --version
to check the version currently installed.
Docker version 19.03.5, build 633a0ea
Before going further, it is necessary now to login with your Docker Hub ID. You should already have created one before this or the previous workshop. If you need to create an ID now go to https://hub.docker.com to register.
Docker login:.
Login with your Docker ID to push and pull images from Docker Hub.
If you don't have a Docker ID, head over to https://hub.docker.com
to create one.
Username: YOUR_DOCKER_ID_HERE
Password:
Login Succeeded
$
Note: if you do not login first you will receive an error message when trying to start docker in the next steps.
Today’s workshop will be an exploration of docker images that provide a graphical interface, either web-based or X11-based. (The latter might not work easily on Windows.)
We’ll explore web-based and X11
examples which are the 2 major but very different graphical interfaces:
Web based:
NGINX
web serverDovex
Python tool with web interface to explore datasetsR/RStudio
web-based server version for the R
interface(For a quick overview see section "webapps with docker" online2.)
X11
-based:
X11
software IGV
genome viewerX11
utilitiesIn casual terms a container is running software on top of a host machine but without direct connection to the host files (unless a shared folder is specified) and without connections to the outside. In other words the container is almost like a box without a lid.
In simple terms, communication in and out the computer is done via specific “openings” called ports. For example, the port of an ssh
connection is port 22
. The default port for a web connection is port 80
. A port is usually associated with a “protocol” which would be “Hypertext Transfer Protocol” or http
for the web.
(For more details see Wikipedia links for “Port (computer networking)”3 and “well-known port numbers”4 )
This is important as we’ll have to know or specify (or both) which port are available for our purpose(s).
Note: The local computer is assigned a special web address which can be written in two equivalent ways:
First of all this option is more “tricky” than the web options and might not work in all circumstances, and even less likely on a Windows computer. Hopefully the examples provided will prove useful.
Citing Wikipedia5: The X Window System(Scheifler and Gettys (1987)) (X11, or simply X) is a windowing system for bitmap displays, common on Unix-like operating systems.
As a first exercise we’ll pull
a docker image for a simple web server running over the linux implementation alpine
seen in a previous workshop.
For this simple test we’ll use the official NGINX docker image. NGINX is open source software for web serving […].6
The docker hub page for this image is: https://hub.docker.com/_/nginx
The purpose of this container is to run a web server, and therefore it is likely that there will be some version of “entry point” (see previous workshop) that will start the web server as soon as the container is activated. This may be suggested from the information provided by the hub page.
The docker file is available online at https://github.com/nginxinc/docker-nginx/blob/master/stable/alpine-perl/Dockerfile and it ends with the following three statements, two of them will be useful later:
The last line with CMD
defines a default behavior when the container is started without specifying a command to be executed. In this case it would start the nginx web server, therefore not allowing shell access by default.
Note: CMD
can be bypassed simply by adding a command at the end of a docker run
command e.g. adding /bin/bash
to open a shell.
In contrast an ENTRYPOINT
command is mandatory and can only be bypassed by adding e.g. --entrypoint /bin/bash
in the the docker run
command.
For more on CMD
and ENTRYPOINT
see this blog entry7: “Docker RUN vs CMD vs ENTRYPOINT” - (lso archived at bit.ly/2WPDME2
pull NGIX image.
We can list images with:
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 540a289bab6c 2 weeks ago 126MB
In this section we’ll try a few versions for the docker run
command to learn about opening and finding ports and other useful information.
There are many options that can be listed via command: docker run --help
.
In this first attempt we’ll use the -P
modifier defined by help as:
-P, --publish-all Publish all exposed ports to random ports
This -P
option will allow to map the ports, but as it is said in the help the mapping will be to a random number. We’ll detail below what that really means.
We’ll also introduce --name
to provide a specific name designation of our choosing rather than a random name given to the container. This will help below to have a “standard” command for e.g. addressing the container. In other words, the commands will work for every user. The name chosen below is simply ng1
.
Run command.
The $
terminal shell prompt is not reappearing, which means that the container is active. However, this terminal is no longer useable for anything else at the moment i.e. we cannot type any more commands, even addressed to the local host. Therefore it is necessary to open a new terminal for any command we want to issue on the local host.
Shell
> New Window
> Basic
(or another colored option.)PowerShell
The docker run
command above named the container ng1
and -P
exposed the container ports to random port(s) on the host. We can find out what the random port is as shown below.
On the new terminal window type the following command using the name of the container:
80/tcp -> 0.0.0.0:32777
(Note: We could also see this information with docker ps
under the PORTS
column as shown below.)
In this example we see that port 80
which we saw earlier is the standard default port number for a web server is mapped to port 32777
which means that port 80
of the container would be connected to port 32777
on the local host (the computer you are using.)
Therefore you should be able to see the content of the web site in the container with the following web address with a web browser on your computer:
http://localhost:32777
Note: Adapt the port number to what you will see on your own terminal. The random aspect of -P
means that the number on the local host might not be always the same. So we’ll fix this in the next section.
This is what you’ll see:
Summary: we were able to start a container running a web site and accessing the site from a browser running on the local computer.
We’ll see shortly that this can be very useful to run specific web-based software.
From this alternative terminal we can also see information about running containers with:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bdadff9f3c9f nginx "nginx -g 'daemon of…" 24 minutes ago Up 24 minutes 0.0.0.0:32777->80/tcp ng1
The output is long an wraps, so it may be clearer to use the followiong command to only see the right-hand part:
PORTS NAMES
0.0.0.0:32768->80/tcp ng1
Turn off container.
There are 2 ways to turn off this container:
docker stop ng1
. Since we started the container with --rm
it will be automatically deleted when it is stopped.With this final, complete command we’ll address useful or necessary points.
-d
) In the previous tests we had to use a secondary terminal because the prompt was not given back after launching the container. This can be changed and the container can be made to run in the background with the “detach” modifier as detailed in help: -d, --detach Run container in background and print container ID
. -d
will allow the shell prompt back, in effect placing the container processes in the background.--name
) as above we’ll specify a name of our choosing to designate the container. Here we’ll call it ng2
.-v
) this provides a channel of communication for data exchange between the container and the host file system. The folder /data
will be created within the container and share all files from the dedicated host folder e.g. $HOME/dockershare
. (See Appendix A.)-p
) We’ll map the relevant port (port 80
) to a port number of our own choosing with the -p
(lower case) option.From help:
-p, --publish list Publish a container's port(s) to the host
.
Typical example mapped port names could be: 8080
, 8787
, 8888
.
Start new, detached container with shared folder.
aac92902b04e7819a35ab3abb0a2d485689fa980da37842b125c6bf251753f5d
Thanks to the -d
flad we get the prompt back after the long name of the container is echoed on the screen. We can check the state of the container with the command: docker ps
or docker container ls
both providing the same output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aac92902b04e nginx "nginx -g 'daemon of…" 3 minutes ago Up 3 minutes 0.0.0.0:8080->80/tcp ng2
We can note that the PORTS
column contains 0.0.0.0:8080->80/tcp
reflecting the port mapping.
We can now test if the web site works after opening a web browser to the local host address:
http://localhost:8080
Note that since we defined the port ourselves there is no randomness to this 8080
assignment.
EXERCISE:
Time permitting We can create a simple document and view it in the web browser.
exec
command that we learned in a previous workshsop. Since the container is detached we can use the same Terminal session with the command:root@aac92902b04e:/#
Therefore the next commands will be issued within the container.
/usr/share/nginx/html
. Therefore we need to make our file mytestfile.html
available at this location. One easy way is to simply copy it there, remembering that within the container the shared folder is called /data
:(Note: If you are more familiar with bash
an alternative would be to use a symbolic link (with ln -s
) to the HTML file or a complete folder. This would be most useful for large size files, data files or folders.)
We can now check if this work within the web browser with the local web address:
http://localhost:8080/mytestfile.html
If all went according to plan, you should see this in your browser:
We can now exit the container bash
session. This will return us to the local host $
prompt.
$
Important Note: Since the container was created as detached the exit
command here only takes us out of the exec
session of bash
initiated thereafter. Therefore the container is still running in the background, which is expected and wanted behavior. You can verify that this is true in 2 ways:
docker ps
command and see that the container is still active.Stop the container.
Now that we are done with this project we need to stop the container and delete it. Since we started the container with --rm
when it is stopped it will be automatically removed. (Otherwise the docker rm
command would be needed.)
ng2
Note: We can verify that this worked by checking with docker ps
.
This next brief exercise is based on Dovex
a web based tool to quickly provide an interactive overview and enable quick exploration of datasets from Melbourne Bioinformatics8 software collection.
The purpose of Dovex
is to help inspect and explore tabular datasets in the form of summaries but also on a large number of optional graphical interactive plots.
Dovex
has been tested on Python 3 and can be installed on the local computer. However, running or installing Python software should not be difficult, but it is often confusing. Running Dovex
from a docker container will alleviate any necessary installation of Python on the local computer.
pull dovex image. :latest
is assumed.
We can list images with:
REPOSITORY TAG IMAGE ID CREATED SIZE
supernifty/dovex latest 8b7d9debceef 6 months ago 1.24GB
The documentation says that 2 datasets are provided. This is true for the online test version of Dovex
9.
The documentation (see below) also states that the 2 datasets are located within /app/uploads
on the container, and that assumes that the web interface has access to this directory.
We’ll use one of them (Iris dataset) that we can download from the Machine Learning archive web page archive.ics.uci.edu/ml/datasets/Iris which provides detailed information.