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
> Applications are safer in containers and Docker provides the strongest default isolation capabilities in the industry
73
72
74
-
- But so do most others
75
73
- 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?
80
75
81
76
---
82
77
@@ -85,19 +80,18 @@ slideOptions:
85
80
- Shares many similarities with VMs, but
86
81
- Lightweight alternative to VMs
87
82
- Stricter limitations than VMs
83
+
- Often different use cases and working together
88
84
- Many different containers solutions
89
85
- 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.
- 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`
71
23
- 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`
72
24
73
25
- 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`
76
29
- Reattach to container `docker container attach tutorial`
77
-
- After quitting again show `docker ps -a`
30
+
- After quitting again, show `docker ps -a`
78
31
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
80
41
81
42
- We can change files inside the container.
82
43
-`docker run -i -t ubuntu /bin/bash`
83
44
-`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`
86
47
- File is not present because we implicitly created a new container based on the same image.
87
48
88
-
## Detached Containers
49
+
## Bind Mount
89
50
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`
91
52
- 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`.
93
54
- Bind mount your source code for development for example
94
55
- 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
-
```
107
56
108
-
Also interesting quote
57
+
## Demo: Building own example
109
58
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.
- 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
118
64
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
+
```
120
70
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 .`
133
72
-`docker run -i -t testimage /bin/bash`
134
73
-`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.
137
74
- 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.
139
75
- When going into the container we are in the directory `/app` and the file `testfile` is present.
140
76
- Copy files with `docker cp`. `touch file-to-copy`
141
77
-`docker cp file-to-copy CONTAINERNAME:/app`
142
78
-`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
148
81
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`.
0 commit comments