Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(notes): add workshop notes #2

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions notes/01_environment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Docker Environment

## Installing Docker
You can install Docker by following the instructions on the [official Docker website](https://docs.docker.com/get-docker/).

## Docker Desktop
If you are using Windows or macOS, you can install Docker Desktop. Docker Desktop is a tool that allows you to run Docker containers on your local machine. You can download Docker Desktop from the [official Docker website](https://www.docker.com/products/docker-desktop).

## Running your first container
To run your first container, you can use the following command:
```bash
docker run hello-world
```
49 changes: 49 additions & 0 deletions notes/02_first_steps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# First Steps

Meine Umgebung
- Windows 11
- WSL2
- Docker Desktop

Switching from windows to linux containers
- Right click on the docker icon in the taskbar
- Select "Switch to Linux containers"

```bash

# Run a container
docker run hello-world
docker run -d nginx

# Show containers
docker ps
docker ps -a

# Inspect a container
docker inspect <container_id>

# Stop a container
docker stop <container_id>

# Start a container
docker start <container_id>

# Delete a container
docker stop <container_id>
docker rm <container_id>
docker rm -f <container_id>

# Not having to type the full container id
docker rm <container_start_of_id>

# Giving a container a name
docker run --name webserver1 -d nginx

# Exec into a container
docker exec -it <container_name> bash

# -it vs -d
# Zu vergleichen mit Windows Fenster, dass sich schließt, wenn das Programm beendet ist
docker run -d nginx
docker run -it nginx
```
27 changes: 27 additions & 0 deletions notes/03_running_a_webserver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Running a webserver

```bash
# Expose a port
docker run -d -p 8080:80 --name webserver1 nginx

# Example with Windows Containers
docker run -d -p 8000:80 --name my-running-site mcr.microsoft.com/windows/servercore/iis

# Logs anschauen
# Zu vergleichen mit Ereignisanzeige
# Auf Std Out und Std Err
docker logs <container_name>
docker logs -f <container_name>

# Edit the default web page
docker exec -it webserver1 bash
echo "Hello World" > /usr/share/nginx/html/index.html

# Expose a second webserver
docker run -d -p 8081:80 --name webserver2 httpd

# Networks
docker network ls
docker network inspect bridge
docker network inspect host
```
19 changes: 19 additions & 0 deletions notes/04_volumes_and_storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Volumes and Storage

Bild zeichnen
Pods erstellen und die default webseite in einem Volume speichern

```bash
# bind mount
docker run -d -p 8080:80 --name webserver1 -v <host_dir>:/usr/share/nginx/html nginx
# show in docker desktop
# show in explorer

# Volume
# Löscht den Inhalt des Volumes nicht
docker volume ls
docker volume create my_volume
docker volume inspect <volume_name>

docker run -d -p 8080:80 --name webserver1 -v my_volume:/usr/share/nginx/html nginx
```
16 changes: 16 additions & 0 deletions notes/05_recap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Recap vom ersten Teil

Pods erstellen und die default webseite anzeigen/bearbeiten

```bash
# Containers
docker ps -a
# Networks
docker network ls
# Volumes
docker volume ls

# Configure a container with env vars
docker run -d -p 8080:8080 kodekloud/webapp-color
docker run -d -p 8080:8080 -e APP_COLOR=green kodekloud/webapp-color
```
24 changes: 24 additions & 0 deletions notes/06_building_images.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Eigene Images erstellen

Eigene Images

```bash
# Alle Images anzeigen
docker images

# Image Tags
# Image Layers
# Dockerfile

docker build .
docker build -t my-webserver:0.0.1 .
docker build -t svengerber/my-webserver:0.0.1 .

docker login
docker push svengerber/my-webserver:0.0.1
docker logout

# Multi-Stage Builds
docker build -t hello .
docker run -p 8080:8080 -it hello
```
12 changes: 12 additions & 0 deletions notes/06_custom_image/multi-stage/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM bitnami/golang:1.13 as builder
RUN go get github.com/urfave/negroni
COPY server.go /
RUN CGO_ENABLED=0 GOOS=linux go build -o /server /server.go

FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /app/
COPY --from=builder /server /app/server
COPY page.html .
ENV PORT=8080
ENTRYPOINT ["/app/server"]
8 changes: 8 additions & 0 deletions notes/06_custom_image/multi-stage/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Hello From my Mini Container</title>
</head>
<body>
<strong>Hello From my Mini Container!</strong>
</body>
</html>
22 changes: 22 additions & 0 deletions notes/06_custom_image/multi-stage/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"fmt"
"io/ioutil"
"net/http"

"github.com/urfave/negroni"
)

func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
t, _ := ioutil.ReadFile("page.html")
fmt.Fprintf(w, string(t))
})

n := negroni.Classic()
n.UseHandler(mux)

n.Run()
}
15 changes: 15 additions & 0 deletions notes/06_custom_image/simple/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM nginx:1.25.3

COPY index.html /usr/share/nginx/html/index.html
COPY confetti.gif /usr/share/nginx/html/confetti.gif

LABEL maintainer="Sven Gerber"

EXPOSE 80

RUN touch /usr/share/nginx/html/myfile.html
RUN echo "Hello World" > /usr/share/nginx/html/myfile.html

#USER myuser:mygroup

CMD ["nginx", "-g", "daemon off;"]
Binary file added notes/06_custom_image/simple/confetti.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions notes/06_custom_image/simple/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Custom Image</title>
</head>
<body>
<h1>Hello from my custom image</h1>
<p>This is a custom image.</p>
<img src="./confetti.gif" alt="Confetti">
</body>
</html>
11 changes: 11 additions & 0 deletions notes/07_docker_compose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Docker Compose

Abhängigkeiten zwischen Containern verwalten

```bash
# Docker Compose File erklären

# Der Sinn von Docker Compose
docker compose up
docker compose up -d
```
31 changes: 31 additions & 0 deletions notes/07_docker_compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
db:
image: mariadb:10.6.4-focal
command: '--default-authentication-plugin=mysql_native_password'
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=somewordpress
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=wordpress
expose:
- 3306
- 33060
wordpress:
image: wordpress:latest
volumes:
- wp_data:/var/www/html
ports:
- 8080:80
- 8443:443
restart: always
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
volumes:
db_data:
wp_data: