* .highlight[Docker Enterprise Edition (EE)] is the paid version of Docker,
with extensive official support, certifications, priority updates, long term support,
extra features, and private image hosting. A "batteries included" version.
* .highlight[Docker Community Edition (CE)] is the open-source, free version of
Docker provided directly by Docker that anyone can install on compatible systems,
but has limited support. A "your own risk" version.
Your Linux distribution may have its own maintained version of Docker
(based on the open-source version). This has no direct support for Docker,
instead it's on your distro's maintainers to keep it up to date and solve issues.
---
## Docker Desktop
For Windows and MacOS, Docker provides a package called .highlight[Docker Desktop]
that simplifies running Docker under those systems.
It's important to stress out that those packages run a base Linux system as a VM
using one of the OS-appropriate methods as the base for running Docker.
On Windows, this requires either Hyper-V (compatible hardware + Pro version or higher)
or WSL2 (requires latest Windows 10 2004).
Also, Docker Desktop on Windows allows managing Windows containers (under Hyper-V).
---
class: center, middle
# Using Docker
---
## Installing Docker
This course assumes a Docker Engine CE installation (on Linux).
I will provide the standard procedure for Ubuntu Linux.
If you're using your own Linux, please proceed with the installation
of Docker CE as per [documentation](https://docs.docker.com/engine/install/).
If your distribution isn't listed, you'll need to look up installation instructions
yourself.
If you do not want to use your own Linux, please ensure at this point that
you can connect to the training system.
---
## Installing Docker (Ubuntu)
To install Docker on Ubuntu, we'll follow the documentation
at [https://docs.docker.com/engine/install/ubuntu/](https://docs.docker.com/engine/install/ubuntu/)
There's also a convenience script at [https://get.docker.com/](https://get.docker.com/)
.exercise[
If you're using your own Ubuntu Linux, follow the instructions.
If you're using your own other Linux, install Docker independently.
If you're using the training VM, you don't need to do anything here
other than try to connect to the system with SSH.
]
---
## Hello, Docker!
If Docker is properly installed, we should be able to run our first container.
```
$ sudo docker run hello-world
```
.exercise[
Run this on your system.
]
--
If successful, this will give some technical output, then:
```
Hello from Docker!
This message shows that your installation appears to be working correctly.
```
Followed by an explanation of what just happened. Let's go over than in more detail.
---
## Aside: why `sudo`?
Docker daemon runs with high privileges, and interacting with it requires
similarly high privileges.
By default, you need to be effective `root` (using `sudo`) to interact with it.
Docker installation normally creates a group `docker` which is authorized to
run `docker` without access to normal `sudo`.
--
However, it must be stressed: .highlight[Having access to the Docker daemon can allow privilege escalation to `root`.] So assigning the `docker` group to a user is as dangerous as allowing `sudo` and is mostly just a convenience.
.note[
To switch to using the `docker` group after using `sudo`,
you probably need to fix permissions:
```
$ sudo chown -R username:username ~/.docker
```
]
---
## Hello, Docker! (in slo-mo, pt. 1)
Running the `docker` command runs a Docker .highlight[client]
that talks to a locally running Docker daemon.
`docker run hello-world` is a command to create a new .highlight[container]
using an .highlight[image] specified by `hello-world`.
Assuming a fresh install of Docker, no such image exists locally
(in the images cached for the current user).
Therefore, Docker looks for the image in configured registries,
which is Docker Hub by default.
---
## Image name specification
Generally, images in a registry are organized by two components:
a .highlight[name] and a .highlight[tag]:
```
name:tag
```
For Docker Hub, except for a few handpicked images, the name must be
.highlight[namespaced] with the Docker user ID, e.g. `godlovedc/lolcow`
means an image `lolcow` from user `godlovedc`.
Tags are a way to version multiple images of the same name.
Specifying a tag is optional: it defaults to a tag named `latest`
(which does not have any special semantics, just a fixed name, like `master` in Git).
So `docker run hello-world` is looking for an image named `hello-world`
and its tag `latest`.
---
## Hello, Docker! (in slo-mo, pt. 2)
Not finding an image `hello-world:latest` in the local cache,
Docker contacts the registry at Docker Hub for it, and finds this:
to be spread between multiple systems, be scaled to multiple load-balanced
instances, etc.
Examples of orchestration tools:
* Docker Swarm
* Kubernetes (or "k8s")
Orchestration is beyond the scope of this course.
---
class: center, middle
# Docker vs Singularity
## Why did another technology emerge?
<!-- ---
# Docker
* Docker came about in 2013 and since has been on a meteoric rise
as the golden standard for containerization technology.
* A huge amount of tools is built around Docker to build, run,
orchestrate and integrate Docker containers.
* Many cloud service providers can directly integrate Docker containers.
Docker claims x26 resource efficiency improvement at cloud scale.
* Docker encourages splitting software into microservice chunks
that can be portably used as needed. -->
---
## Docker concerns
* Docker uses a pretty complicated model of images/volumes/metadata,
orchestrating swarms of those containers to work together,
and it not always very transparent with how those are stored.
* Also, isolation features require superuser privileges;
Docker has a persistent daemon running with those privileges
and many container operations require root as well.
--
Both of those issues make Docker undesirable in applications
where you don't wholly own the computing resource - HPC environments.
Out of those concerns, and out of scientific community, came Singularity.
---
## Singularity
Singularity was created in 2016 as an HPC-friendly alternative to Docker.
It is still in rapid development.
--
* It's usually straightforward to convert a Docker container to a Singularity image.
This gives users access to a vast library of containers.
--
* Singularity uses a monolithic, image-file based approach.
Instead of dynamically overlaid layers.
You build a single file on one system and simply copy it over or archive it.
This addresses the "complex storage" issue with Docker.
---
## Singularity and root privileges
The privilege problem was a concern from the ground-up,
to make Singularity acceptable for academic clusters.
--
* Addressed by having a `setuid`-enabled binary that can
accomplish container startup and drop privileges ASAP.
--
* Privilege elevation inside a container is impossible:
`setuid` mechanism is disabled inside the container,
so to be root inside, you have to be root outside.
* Recent `--fakeroot` option allows for administrative actions
inside the container, without affecting effective access to the host.
--
* Users don't need explicit root access to operate containers
(at least after the initial build).
---
## Singularity and HPC
Thanks to the above improvements over Docker, HPC cluster operators
are much more welcoming to the idea of Singularity support.
As a result of a joint Pipeline Interoperability project between Swiss Science IT groups, the UniBE Linux cluser UBELIX started to support Singularity.
Once your software is packaged in Singularity, it should work across
all Science IT platforms supporting the technology.
---
## Singularity niche
When is Singularity useful over Docker?
* The major use case was and still is .highlight[shared systems]:
systems where unprivileged users need the ability to run containers.
However, an admin still needs to install Singularity for it
to function.
* Singularity is useful as an alternative to Docker. If you have admin privileges on the host, Singularity can do more
than in unprivileged mode.
It doesn't have the same level of ecosystem around it,
but currently gaining features such as OCI runtime
interface, native Kubernetes integration and own cloud services.
---
## Singularity "sales pitch"
Quoting from Singularity Admin documentation:
> _Untrusted users (those who don’t have root access and aren’t getting it) can run untrusted containers (those that have not been vetted by admins) safely._
This won over quite a few academic users; for a sampling: