Docker
Introduction to Docker
What is Docker?
Platform for developing, shipping and running applications.
Infrastructure as application / code.
First version: 2013.
Company: originally dotCloud (2010), later named Docker.
Established Open Container Initiative.
As a software:
Docker Enterprise Edition.
There is an increasing number of alternative container technologies and providers. Many of them are based on software components originally from the Docker stack, and they usually try to address some specific use cases or weak points. As an example, Singularity, which we introduce later in this course, is focused on HPC environments.
Another case, Podman <https://podman.io> keeps high functional compatibility with Docker but with a different focus on technology (not keeping a daemon) and permissions. We will use Podman in this course.
docker
command will be an alias of podman
in our environment.
Docker components
Read-only templates.
Containers are run from them.
Images are not run.
Images have several layers.
Images versus containers
Image: A set of layers, read-only templates, inert.
An instance of an image is called a container.
When you start an image, you have a running container of this image. You can have many running containers of the same image.
“The image is the recipe, the container is the cake; you can make as many cakes as you like with a given recipe.”
Podman setup
Place the following bit of code in ~/.config/containers/storage.conf
:
[storage]
driver = "overlay"
graphroot = "/tmp/podman/$USER/.local/share/containers/storage"
[storage.options]
mount_program = "/usr/bin/fuse-overlayfs"
ignore_chown_errors = "true"
Docker vocabulary
docker
Get help:
docker run --help
Using existing images
Explore Docker hub
Images can be stored locally or shared in a registry.
Docker hub is the main public registry for Docker images.
Let’s search the keyword ubuntu:
docker pull: import image
get latest image / latest release
docker pull ubuntu
choose the version of Ubuntu you are fetching: check the different tags
docker pull ubuntu:22.04
Biocontainers
Specific directory of Bioinformatics related entries
Entries in Docker hub and/or Quay.io (RedHat registry)
Normally created from Bioconda
Example: FastQC
https://biocontainers.pro/#/tools/fastqc
docker pull biocontainers/fastqc:v0.11.9_cv7
docker images: list images
docker images
Each image has a unique IMAGE ID.
docker run: run image, i.e. start a container
Now we want to use what is inside the image.
docker run creates a fresh container (active instance of the image) from a Docker (static) image, and runs it.
The format is:
docker run image:tag command
docker run ubuntu:22.04 /bin/ls
Now execute ls in your current working directory: is the result the same?
You can execute any program/command that is stored inside the image:
docker run ubuntu:22.04 /bin/whoami
docker run ubuntu:22.04 cat /etc/issue
You can either execute programs in the image from the command line (see above) or execute a container interactively, i.e. “enter” the container.
docker run -it ubuntu:22.04 /bin/bash
Run container as daemon (in background)
docker run --detach ubuntu:22.04 tail -f /dev/null
Run container as daemon (in background) with a given name
docker run --detach --name myubuntu ubuntu:22.04 tail -f /dev/null
docker ps: check containers status
List running containers:
docker ps
List all containers (whether they are running or not):
docker ps -a
Each container has a unique ID.
docker exec: execute process in running container
docker exec myubuntu uname -a
Interactively
docker exec -it myubuntu /bin/bash
docker rm, docker rmi: clean up!
docker rm myubuntu
docker rm -f myubuntu
docker rmi ubuntu:22.04
Major clean
Check used space
docker system df
Remove unused containers (and others) - DO WITH CARE
docker system prune
Remove ALL non-running containers, images, etc. - DO WITH MUCH MORE CARE!!!
docker system prune -a
Volumes
Docker containers are fully isolated. It is necessary to mount volumes in order to handle input/output files.
Syntax: --volume/-v host:container
mkdir test
touch test/test
docker run --detach --volume $(pwd)/test:/scratch --name fastqc_container biocontainers/fastqc:v0.11.9_cv7 tail -f /dev/null
docker exec -ti fastqc_container /bin/bash
> ls -l /scratch
> exit