Skip to content

Commit 8ba5d5b

Browse files
authored
Update vm/containers chapter for WS24/25 (#197)
1 parent df58137 commit 8ba5d5b

13 files changed

+288
-539
lines changed

02_virtualization_and_containers/containers_demo.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

02_virtualization_and_containers/containers_slides.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ slideOptions:
3232
<img src="https://raw.githubusercontent.com/Simulation-Software-Engineering/Lecture-Material/main/02_virtualization_and_containers/figs/container-sketch.png" width=30%; style="margin-left:auto; margin-right:auto; padding-top: 25px; padding-bottom: 25px">
3333

3434
- Container operates in "fenced off" part of the operating system (`namespaces`)
35-
- Low(er) overhead than virtual machines
35+
- Lower overhead than virtual machines
3636
- Runs on kernel (and libraries) of the host OS
3737
- Cheap to start and stop a container
38-
- Available features depend on Host
39-
- Linux container on Windows or vice versa?
38+
- Available features depend on Host (Linux, Windows)
4039
- Container can be isolated.
4140

4241
---
@@ -47,36 +46,32 @@ slideOptions:
4746
- Reproducible environments for developing and testing (DevOps)
4847
- Container hype strongly driven by [Docker](https://www.docker.com/).
4948
- More and more in science
50-
- High-performance computing, "Bring Your Own Environment" (BYOE)
49+
- High-performance computing, "Bring Your Own Environment"
5150
- Reproducible research
5251

5352
---
5453

5554
## Container Solutions
5655

5756
- Plenty of different container formats
58-
- [lxc/lxd](https://linuxcontainers.org/), [Docker](https://www.docker.com/), [Singularity](https://sylabs.io/), [podman](https://podman.io/), [Sarus](https://user.cscs.ch/tools/containers/sarus/)...
57+
- [lxc/lxd](https://linuxcontainers.org/), [Docker](https://www.docker.com/), [Apptainer](https://apptainer.org/), [podman](https://podman.io/), [Sarus](https://user.cscs.ch/tools/containers/sarus/)...
5958
- Different solutions with different strengths due to different use cases
60-
- (Super-)Userspace
61-
- Direct access to hardware (memory, storage, GPUs) vs. encapsulation
62-
- Generic or with integration in software ecosystem (e.g. schedulers)
59+
- Working on the (Super-)Userspace
60+
- Direct access to hardware vs. encapsulation
61+
- Generic or with integration in software ecosystem (e.g. job schedulers)
6362
- Effort to establish certain standards
6463
- [Open Container Initiative (OCI)](https://opencontainers.org/)
6564

6665
---
6766

6867
## Security
6968

70-
- Docker considers itself safe
69+
- Containers are isolated
7170

7271
> Applications are safer in containers and Docker provides the strongest default isolation capabilities in the industry
7372
74-
- But so do most others
7573
- Read the manual
76-
- Are third-part containers trust worthy?
77-
- There have been cases [of malicious images](https://www.trendmicro.com/vinfo/fr/security/news/virtualization-and-cloud/malicious-docker-hub-container-images-cryptocurrency-mining)
78-
- Containers isolation from Host depends on container framework
79-
- Think about **what** you do, **before** you do it
74+
- Are third-part containers trust-worthy?
8075

8176
---
8277

@@ -85,19 +80,18 @@ slideOptions:
8580
- Shares many similarities with VMs, but
8681
- Lightweight alternative to VMs
8782
- Stricter limitations than VMs
83+
- Often different use cases and working together
8884
- Many different containers solutions
8985
- Standardization effort
90-
- Choose right container for your use case
91-
92-
**Note**: Do not (only) use containers for shipping your software. Not everyone can run/use them.
86+
- Choose right solution for your use case
9387

9488
---
9589

9690
## Further Reading
9791

9892
- [Docker](https://www.docker.com/)
9993
- [Docker Hub](https://hub.docker.com/)
100-
- [Singularity](https://sylabs.io/)
94+
- [Apptainer](https://apptainer.org/)
10195
- [Sarus](https://user.cscs.ch/tools/containers/sarus/)
10296
- [lxc/lxd](https://linuxcontainers.org/)
10397
- [podman](https://podman.io/)
Lines changed: 34 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,13 @@
11
# Docker Demo
22

3-
## Introduction to Docker and Some Practical Examples
4-
5-
- The most popular container framework one finds at the moment
6-
- Short backstory:
7-
- Started as wrapper around lxc/lxd (Linux' native container format)
8-
- Docker, Docker Engine, Docker Compose, Docker Hub? What is going on?
9-
- Server-client layout
10-
- Quite strong encapsulation from Host (**TODO**: Check for file exchange, networking etc.)
11-
- **Generally useful commands** (see slides as well)
12-
- `docker run OPTIONS`
13-
- Run a container
14-
- `docker image ls`
15-
- List locally available images
16-
- `docker pull NAME:TAG`
17-
- Pulls an image from registry, `TAG` optional
18-
- `docker container create IMAGE`
19-
- Create container from image
20-
- `docker container ls`
21-
- List running containers
22-
- Add `-a` to see all containers
23-
- `docker container start/stop NAME`
24-
- Start/stop container
25-
- `docker container attach NAME`
26-
- Attach to running container
27-
- `docker build`
28-
- Creates an image from a given Dockerfile
29-
- `docker cp`
30-
- Copy files in/out of container
31-
- `docker image history IMAGE`
32-
- Show layers of image (including commands)Vagrant
33-
- `docker system prune`
34-
- Remove all unused objects (images, containers...)
35-
- `docker logs ID/NAME`
36-
- Shows log files of container
37-
- `docker commit ID USER/NAME:TAG`
38-
- Commit a container to an image
39-
- Explain text-based format (infrastructure as code)
40-
- One can pre-build own images to reuse them later.
41-
- Has a layer based build process (which is nice). We do not have to rebuild from scratch, if build fails.
42-
- Images can be shared via DockerHub or other registries
43-
- Building an image can be pain in the neck as it depends on a fast internet connection.
44-
- Installation issue/security risks: Docker user group is basically root
45-
- Rootless installation of Docker
46-
- Namespaces
47-
- Docker considers itself quite safe
48-
- We focus on tools to create, run and interact with containers.
49-
- Example of a tool which uses Docker: - [`act`](https://github.com/nektos/act) is a tool to debug/run GitHub actions locally
50-
51-
Source: [https://docs.docker.com/get-started/overview/](https://docs.docker.com/get-started/overview/)
3+
- Show containers on [DockerHub](https://hub.docker.com/)
524

535
## Some Management Commands
546

557
- Show running containers `docker container ls`
568
- Show all containers `docker container ls -a`
579
- Show images `docker images`
58-
- Remove some image/container `docker image rm NAME` or `docker container rm NAME/ID`
10+
- Potentially remove some image/container `docker image rm NAME` or `docker container rm NAME/ID`
5911

6012
## Tutorial Case
6113

@@ -67,85 +19,63 @@ Source: [https://docs.docker.com/get-started/overview/](https://docs.docker.com/
6719
- Starts container and runs `/bin/bash`
6820
- `-i` means interactive
6921
- `-t` allocates pseudo-tty
70-
- Note that the container will still be there `docker container list -a`.
22+
- Note that the container will still be there `docker container list -a` vs. `docker container list -a`
7123
- We can make sure that the container is removed after exiting by the `--rm` options, i.e., `docker run --rm -i -t ubuntu /bin/bash`
7224

7325
- When container is running, we see it when calling `docker ps`
74-
- Start container (with name `tutorial`) `docker run --rm -i -t --name tutorial ubuntu /bin/bash`
75-
- Leave it `CTRL-P` + `CTRL-Q` (do not let go of `CTRL` while doing this)
26+
- Start container (with name `tutoral`) `docker run --rm -i -t --name tutorial ubuntu /bin/bash`
27+
- Leave it `CTRL-P-Q` (all keys pressed at the same time)
28+
- Show container running `docker ps`
7629
- Reattach to container `docker container attach tutorial`
77-
- After quitting again show `docker ps -a`
30+
- After quitting again, show `docker ps -a`
7831

79-
## Files in Containers
32+
## Restarting a stopped container
33+
34+
```shell
35+
docker ps -a
36+
docker container start tutorial
37+
docker container attach tutorial
38+
```
39+
40+
## Files in containers
8041

8142
- We can change files inside the container.
8243
- `docker run -i -t ubuntu /bin/bash`
8344
- `touch asdf`
84-
- Leave container `exit`
85-
- Enter container `docker run -i -t ubuntu /bin/bash`
45+
- leave container
46+
- enter container `docker run -i -t ubuntu /bin/bash`
8647
- File is not present because we implicitly created a new container based on the same image.
8748

88-
## Detached Containers
49+
## Bind Mount
8950

90-
- `docker run -d -i -t --name test --mount type=bind,source="$(pwd)",target=/mnt/share ubuntu`
51+
- `docker run -i -t --mount type=bind,source="$(pwd)",target=/mnt/share ubuntu`
9152
- Create detached container and bind mount
92-
- Will run container in detached mode, names it `test` and mounts current directory on Host to `/mnt/share`. It is based on `ubuntu` image.
53+
- Mounts current directory on Host to `/mnt/share`.
9354
- Bind mount your source code for development for example
9455
- I do not need `/bin/bash` because that is the default command for the `ubuntu` image.
95-
- Enter the container by `docker attach ID`.
96-
97-
## Restarting a Stopped Container With an Arbitrary Command
98-
99-
- This is currently not possible. The default command or entrypoint is part of the runnable container. One has to create a new container from the stopped container to start it with another command.
100-
- See also GitHub issues
101-
- [docker exec into a stopped container](https://github.com/moby/moby/issues/18078). There is also a workaround mentioned in this issue
102-
103-
```bash
104-
docker commit $STOPPED_CONTAINER user/test_image
105-
docker run -ti --entrypoint=sh user/test_image
106-
```
10756

108-
Also interesting quote
57+
## Demo: Building own example
10958

110-
> The main reason why is because containers are supposed to be immutable. You cannot exec into a stopped container because it has be be running first.
59+
- `cd dockerfile-example`
60+
- Contains Dockerfile
11161

112-
- [`docker exec` in stopped containers](https://github.com/moby/moby/issues/30361)
113-
- See some workaround on [StackOverflow](https://stackoverflow.com/questions/32353055/how-to-start-a-stopped-docker-container-with-a-different-command)
114-
- Find container id `docker container list -a`
115-
- Commit stopped container to save its modified state into a new image `docker commit CONTAINERID USER/IMAGENAME`.
116-
- Start new container with different entry point `docker run -ti --entrypoint=sh USER/IMAGENAME` if an entrypoint is specified in the previews image or `docker run -ti USER/IMAGENAME /bin/sh`.
117-
- For details on the difference between entry points (`ENTRYPOINT`) and the default for executing a container (`CMD`) check the [Dockerfile reference](https://docs.docker.com/engine/reference/builder/).
62+
```Dockerfile
63+
FROM ubuntu:24.04
11864

119-
## Demo: Building own Example
65+
RUN apt-get update -y && apt install -y neofetch
66+
WORKDIR /app
67+
COPY testfile .
68+
CMD ["neofetch"]
69+
```
12070

121-
- Folder containing Dockerfile
122-
123-
```Dockerfile
124-
FROM ubuntu:18.04
125-
126-
RUN apt update -y && apt install -y neofetch
127-
WORKDIR /app
128-
COPY testfile .
129-
CMD ["echo", "hello"]
130-
```
131-
132-
- `docker build --tag testimage .`
71+
- `docker buildx build --tag testimage .`
13372
- `docker run -i -t testimage /bin/bash`
13473
- `docker run testimage` will run container and `CMD` will be executed
135-
- `docker run -d -i -t --name testimage testimage` will immediately terminate since the container `CMD` is executed.
136-
- `docker run -d -i -t --name testimage testimage /bin/bash` keeps container alive since the terminal session is running inside.
13774
- Create file `touch testfile`, if not present.
138-
- `docker run -i -t --name testimage -v $(pwd):/app -w /app testimage /bin/bash` starts container, creates volume `/app` and sets working directory to /app.
13975
- When going into the container we are in the directory `/app` and the file `testfile` is present.
14076
- Copy files with `docker cp`. `touch file-to-copy`
14177
- `docker cp file-to-copy CONTAINERNAME:/app`
14278
- `docker cp CONTAINERNAME:/app file-to-copy`
143-
- This will fix preserve user and group id
144-
145-
## Demo: FEniCS Example
146-
147-
Run `docker run -ti -p 127.0.0.1:8000:8000 -v $(pwd):/home/fenics/shared -w /home/fenics/shared quay.io/fenicsproject/stable:current`
79+
- This will preserve user and group id
80+
- `docker run -i -t -v $(pwd):/app testimage /bin/bash` starts container, creates volume `/app` and sets working directory to /app
14881

149-
- `-v` creates a volume in the container and mounts the current directory on Host to path `/home/fenics/shared` inside the container.
150-
- `-w` sets the working directory to `/home/fenics/shared`.
151-
- Volume allows for persistent data

0 commit comments

Comments
 (0)