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
|Containerized Database with Persistent Storage|Applications|[Exercise](containerized_db_persistent_storage.md)|[Solution](solutions/containerized_db_persistent_storage.md)
10
12
|My First Dockerfile|Dockerfile|[Exercise](write_dockerfile_run_container.md)|
<summary>How to list the container images on certain host?</summary><br><b>
156
159
157
-
CONTAINER_BINARY=podman # or docker
160
+
CONTAINER_BINARY=podman
158
161
$CONTAINER_BINARY images
159
162
```
160
163
@@ -165,7 +168,7 @@ Note: you can also use `$CONTAINER_RUNTIME image ls`
165
168
<summary>How to download/pull a container image without actually running a container?</summary><br><b>
166
169
167
170
```
168
-
CONTAINER_BINARY=podman # or docker
171
+
CONTAINER_BINARY=podman
169
172
$CONTAINER_BINARY pull rhel
170
173
```
171
174
</b></details>
@@ -375,7 +378,7 @@ Cons:
375
378
</b></details>
376
379
377
380
<a name="questions-basic-commands"></a>
378
-
#### Containers - Basic Commands
381
+
### Basic Commands
379
382
380
383
<details>
381
384
<summary>How to list all the containers on a given host?</summary><br><b>
@@ -437,18 +440,73 @@ With the -d flag. It will run in the background and will not attach it to the te
437
440
`docker container run -d httpd` or `podman container run -d httpd`
438
441
</b></details>
439
442
443
+
<details>
444
+
<summary>If you'll run <code>sleep 100</code> inside a container, will you see it when listing all the processes of the host on which the container runs? Why?</summary><br><b>
445
+
</b></details>
446
+
447
+
<details>
448
+
<summary>True or False? If image <code>httpd-service</code> has an entry point for running the httpd service then, the following will run the container and eventually the httpd service <code>podman run httpd-service ls</code></summary><br><b>
449
+
450
+
False. Running that command will override the entry point so the httpd service won't run and instead podman will run the `ls` command.
451
+
</b></details>
452
+
453
+
<details>
454
+
<summary>True or False? Running <code>podman restart CONTAINER_NAME</code> kills the main process inside the container and runs it again from scratch</summary><br><b>
455
+
456
+
False. `podman restart` creates an entirely new container with the same ID while reusing the filesystem and state of the original container.
457
+
</b></details>
458
+
459
+
<a name="questions-containers-storage"></a>
460
+
### Storage
461
+
462
+
<details>
463
+
<summary>Container storage is said to be ephemeral. What does it mean?</summary><br><b>
464
+
465
+
It means the contents of the container and the data generated by it, is gone when the container is removed.
466
+
</b></details>
467
+
468
+
<details>
469
+
<summary>True or False? Applications running on containers, should use the container storage to store persistent data</summary><br><b>
470
+
471
+
False. Containers are not built to store persistent data and even if it's possible with some implementations, it might not perform well in case of applications with intensive I/O operations.
472
+
</b></details>
473
+
474
+
<details>
475
+
<summary>You stopped a running container but, it still uses the storage in case you ever resume it. How to reclaim the storage of a container?</summary><br><b>
440
476
441
-
<a name="questions-volume"></a>
442
-
#### Containers - Volume
477
+
In order to reclaim the storage of a container, you have to remove it.
478
+
</b></details>
443
479
444
480
<details>
445
481
<summary>How to create a new volume?</summary><br><b>
446
482
447
-
`docker volume create some_volume`
483
+
```
484
+
CONTAINER_BINARY=podman
485
+
$CONTAINER_BINARY volume create some_volume
486
+
```
487
+
</b></details>
488
+
489
+
<details>
490
+
<summary>How to mount a directory from the host to a container?</summary><br><b>
491
+
492
+
```
493
+
CONTAINER_BINARY=podman
494
+
mkdir /tmp/dir_on_the_host
495
+
496
+
$CONTAINER_BINARY run -v /tmp/dir_on_the_host:/tmp/dir_on_the_container IMAGE_NAME
497
+
```
498
+
499
+
In some systems you'll have also to adjust security on the host itself:
<summary>True or False? Containers have ephemeral storage layer</summary><br><b>
676
+
677
+
True. The ephemeral storage layer is added on top of the base image layer and is exclusive to the running container. This way, containers created from the same base image, don't share the same storage.
678
+
</b></details>
679
+
616
680
<a name="questions-docker-architecture"></a>
617
-
#### Containers - Docker Architecture
681
+
### Docker Architecture
618
682
619
683
<details>
620
684
<summary>Which components/layers compose the Docker technology?</summary><br><b>
@@ -791,7 +855,7 @@ Because each container has its own writable container layer, and all changes are
791
855
</b></details>
792
856
793
857
<a name="questions-docker-compose"></a>
794
-
#### Containers - Docker Compose
858
+
### Docker Compose
795
859
796
860
<details>
797
861
<summary>Explain what is Docker compose and what is it used for</summary><br><b>
@@ -810,7 +874,7 @@ In general, it's useful for running applications which composed out of several d
810
874
</b></details>
811
875
812
876
<a name="questions-docker-images"></a>
813
-
#### Containers - Docker Images
877
+
### Docker Images
814
878
815
879
<details>
816
880
<summary>What is Docker Hub?</summary><br><b>
@@ -867,7 +931,7 @@ By default, Docker uses everything (all the files and directories) in the direct
867
931
</b></details>
868
932
869
933
<a name="questions-networking"></a>
870
-
#### Containers - Networking
934
+
### Networking
871
935
872
936
<details>
873
937
<summary>What container network standards or architectures are you familiar with?</summary><br><b>
Historically, user needed root privileges to run containers. One of the most basic security recommendations is to provide users with minimum privileges for what they need.
1047
+
1048
+
For containers it's been the situation for a long time and still for running some containers today from docker.io, you'll need to have root privileges.
1049
+
</b></details>
1050
+
1051
+
<details>
1052
+
<summary>Are there disadvantages in running rootless containers?</summary><br><b>
1053
+
1054
+
Yes, the full list can be found [here](https://github.com/containers/podman/blob/main/rootless.md).
1055
+
1056
+
Some worth to mention:
1057
+
1058
+
- No binding to ports smaller than 1024
1059
+
- No images sharing CRI-O or other rootful users
1060
+
- No support running on NFS or parallel filesystem homerdirs
1061
+
- Some commands don't work (mount, podman stats, checkpoint, restore, ...)
1062
+
</b></details>
1063
+
1064
+
<details>
1065
+
<summary>Give one example of rootless containers are more safe from security perspective</summary><br><b>
1066
+
1067
+
In rootless containers, user namespace appears to be running as root but it doesn't, it's executed with regular user privileges. If an attacker manages to get out of the user space to the host with the same privileges, there's not much he can do because it's not root privileges as opposed to containers that run with root privileges.
1068
+
</b></details>
1069
+
1070
+
<details>
1071
+
<summary>When running a container, usually a virtual ethernet device is created. To do so, root privileges are required. How is it then managed in rootless containers?</summary><br><b>
1072
+
1073
+
Networking is usually managed by Slirp in rootless containers. Slirp creates a tap device which is also the default route and it creates it in the network namepsace of the container. This device's file descriptor passed to the parent who runs it in the default namespace and the default namespace connected to the internet. This enables communication externally and internally.
1074
+
</b></details>
1075
+
1076
+
<details>
1077
+
<summary>When running a container, usually a layered file system is created, but it requires root privileges. How is it then managed in rootless containers?</summary><br><b>
1078
+
1079
+
New drivers were created to allow creating filesystems in a user namespaces. Drivers like the FUSE-OverlayFS.
1. Run a container with a database of any type of you prefer (MySql, PostgreSQL, Mongo, etc.)
4
+
2. Verify the container is running
5
+
3. Access the container and create a new table (or collection, depends on which DB type you chose) for students
6
+
4. Insert a row (or document) of a student
7
+
5. Verify the row/document was added
8
+
9
+
10
+
## Solution
11
+
12
+
```
13
+
# Run the container
14
+
podman run --name mysql -e MYSQL_USER=mario -e MYSQL_PASSWORD=tooManyMushrooms -e MYSQL_DATABASE=university -e MYSQL_ROOT_PASSWORD=MushroomsPizza -d mysql
15
+
16
+
# Verify it's running
17
+
podman ps
18
+
19
+
# Add student row to the database
20
+
podman exec -it mysql /bin/bash
21
+
mysql -u root
22
+
use university;
23
+
CREATE TABLE Students (id int NOT NULL, name varchar(255) DEFAULT NULL, PRIMARY KEY (id));
24
+
insert into Projects (id, name) values (1,'Luigi');
0 commit comments