diff --git a/notes/01_environment.md b/notes/01_environment.md new file mode 100644 index 0000000..a4cf774 --- /dev/null +++ b/notes/01_environment.md @@ -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 +``` diff --git a/notes/02_first_steps.md b/notes/02_first_steps.md new file mode 100644 index 0000000..17efc31 --- /dev/null +++ b/notes/02_first_steps.md @@ -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 + +# Stop a container +docker stop + +# Start a container +docker start + +# Delete a container +docker stop +docker rm +docker rm -f + +# Not having to type the full container id +docker rm + +# Giving a container a name +docker run --name webserver1 -d nginx + +# Exec into a container +docker exec -it 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 +``` diff --git a/notes/03_running_a_webserver.md b/notes/03_running_a_webserver.md new file mode 100644 index 0000000..2e30813 --- /dev/null +++ b/notes/03_running_a_webserver.md @@ -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 +docker logs -f + +# 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 +``` diff --git a/notes/04_volumes_and_storage.md b/notes/04_volumes_and_storage.md new file mode 100644 index 0000000..8eb8afd --- /dev/null +++ b/notes/04_volumes_and_storage.md @@ -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 :/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 + +docker run -d -p 8080:80 --name webserver1 -v my_volume:/usr/share/nginx/html nginx +``` diff --git a/notes/05_recap.md b/notes/05_recap.md new file mode 100644 index 0000000..c9add4d --- /dev/null +++ b/notes/05_recap.md @@ -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 +``` diff --git a/notes/06_building_images.md b/notes/06_building_images.md new file mode 100644 index 0000000..fe8509d --- /dev/null +++ b/notes/06_building_images.md @@ -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 +``` diff --git a/notes/06_custom_image/multi-stage/Dockerfile b/notes/06_custom_image/multi-stage/Dockerfile new file mode 100644 index 0000000..af30177 --- /dev/null +++ b/notes/06_custom_image/multi-stage/Dockerfile @@ -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"] \ No newline at end of file diff --git a/notes/06_custom_image/multi-stage/page.html b/notes/06_custom_image/multi-stage/page.html new file mode 100644 index 0000000..4e4dfd9 --- /dev/null +++ b/notes/06_custom_image/multi-stage/page.html @@ -0,0 +1,8 @@ + + + Hello From my Mini Container + + + Hello From my Mini Container! + + \ No newline at end of file diff --git a/notes/06_custom_image/multi-stage/server.go b/notes/06_custom_image/multi-stage/server.go new file mode 100644 index 0000000..a160906 --- /dev/null +++ b/notes/06_custom_image/multi-stage/server.go @@ -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() +} diff --git a/notes/06_custom_image/simple/Dockerfile b/notes/06_custom_image/simple/Dockerfile new file mode 100644 index 0000000..7d2b8ff --- /dev/null +++ b/notes/06_custom_image/simple/Dockerfile @@ -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;"] diff --git a/notes/06_custom_image/simple/confetti.gif b/notes/06_custom_image/simple/confetti.gif new file mode 100644 index 0000000..013df10 Binary files /dev/null and b/notes/06_custom_image/simple/confetti.gif differ diff --git a/notes/06_custom_image/simple/index.html b/notes/06_custom_image/simple/index.html new file mode 100644 index 0000000..7aa5cdf --- /dev/null +++ b/notes/06_custom_image/simple/index.html @@ -0,0 +1,11 @@ + + + + Custom Image + + +

Hello from my custom image

+

This is a custom image.

+ Confetti + + \ No newline at end of file diff --git a/notes/07_docker_compose.md b/notes/07_docker_compose.md new file mode 100644 index 0000000..2212cbe --- /dev/null +++ b/notes/07_docker_compose.md @@ -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 +``` diff --git a/notes/07_docker_compose/docker-compose.yml b/notes/07_docker_compose/docker-compose.yml new file mode 100644 index 0000000..b495e0f --- /dev/null +++ b/notes/07_docker_compose/docker-compose.yml @@ -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: \ No newline at end of file