main
Jonas Arnold 3 years ago
parent 4b1c22ac3f
commit 176b64c793
  1. 3
      ASYD_Docker/README.md
  2. 37
      ASYD_Docker/docker-01/01-demo/Dockerfile
  3. 5
      ASYD_Docker/docker-01/01-demo/build.sh
  4. 8
      ASYD_Docker/docker-01/01-demo/src/ASYD_Demo.csproj
  5. 39
      ASYD_Docker/docker-01/01-demo/src/Program.cs
  6. 13
      ASYD_Docker/docker-02/123deb/solution.md
  7. 34
      ASYD_Docker/docker-02/vol_host/solution.md
  8. 23
      ASYD_Docker/docker-02/vol_named/solution.md
  9. 19
      ASYD_Docker/docker-02/webcp/build.sh
  10. 8
      ASYD_Docker/docker-02/webcp/index.html
  11. 11
      ASYD_Docker/docker-02/webimg/README.txt
  12. 40
      ASYD_Docker/docker-02/webimg/build.sh
  13. 6
      ASYD_Docker/docker-02/webimg/index.html
  14. 6
      ASYD_Docker/docker-03/chello-world/Dockerfile
  15. 23
      ASYD_Docker/docker-03/chello-world/build.sh
  16. BIN
      ASYD_Docker/docker-03/chello-world/hello-world
  17. 6
      ASYD_Docker/docker-03/chello-world/hello-world.c
  18. 4
      ASYD_Docker/docker-03/debcp_v1/Dockerfile
  19. 17
      ASYD_Docker/docker-03/debcp_v1/build.sh
  20. 1
      ASYD_Docker/docker-03/debcp_v1/greetings.txt
  21. 3
      ASYD_Docker/docker-03/debcp_v2/Dockerfile
  22. 17
      ASYD_Docker/docker-03/debcp_v2/build.sh
  23. 3
      ASYD_Docker/docker-03/debcp_v3/Dockerfile
  24. 17
      ASYD_Docker/docker-03/debcp_v3/build.sh
  25. 3
      ASYD_Docker/docker-03/debcp_v3/debcp_v2/Dockerfile
  26. 17
      ASYD_Docker/docker-03/debcp_v3/debcp_v2/build.sh
  27. 8
      ASYD_Docker/docker-03/debcp_v4/Dockerfile
  28. 7
      ASYD_Docker/docker-03/debcp_v4/build.sh
  29. 1
      ASYD_Docker/docker-03/debcp_v4/greetings.txt
  30. 6
      ASYD_Docker/docker-03/debcp_v5/Dockerfile
  31. 20
      ASYD_Docker/docker-03/debcp_v5/build.sh
  32. 17
      ASYD_Docker/docker-03/debcptmp/build.sh
  33. 4
      ASYD_Docker/docker-03/debcptmp/context/Dockerfile
  34. 1
      ASYD_Docker/docker-03/debcptmp/context/greetings.txt
  35. 6
      ASYD_Docker/docker-03/myhelloworld/Dockerfile
  36. BIN
      ASYD_Docker/docker-03/myhelloworld/hello-world
  37. 11
      ASYD_Docker/docker-03/myweb_v1/README.txt
  38. 34
      ASYD_Docker/docker-03/myweb_v1/build.sh
  39. 6
      ASYD_Docker/docker-03/myweb_v1/index.html
  40. 5
      ASYD_Docker/docker-03/myweb_v2/Dockerfile
  41. 3
      ASYD_Docker/docker-03/myweb_v2/build.sh
  42. 6
      ASYD_Docker/docker-03/myweb_v2/index.html
  43. 5
      ASYD_Docker/docker-03/nanodeb_v1/Dockerfile
  44. 3
      ASYD_Docker/docker-03/nanodeb_v1/build.sh
  45. 7
      ASYD_Docker/docker-03/nanodeb_v2/Dockerfile
  46. 3
      ASYD_Docker/docker-03/nanodeb_v2/build.sh
  47. 8
      ASYD_Docker/docker-03/nanodeb_v3/Dockerfile
  48. 3
      ASYD_Docker/docker-03/nanodeb_v3/build.sh
  49. 9
      ASYD_Docker/docker-03/nanodeb_v4/Dockerfile
  50. 3
      ASYD_Docker/docker-03/nanodeb_v4/build.sh
  51. 10
      ASYD_Docker/docker-03/nanodeb_v5/Dockerfile
  52. 3
      ASYD_Docker/docker-03/nanodeb_v5/build.sh
  53. 4
      ASYD_Docker/docker-03/scratch/Dockerfile
  54. 5
      ASYD_Docker/docker-03/scratch/build.sh
  55. BIN
      ASYD_Docker/docker-03/scratch/hello-world1
  56. BIN
      ASYD_Docker/docker-03/scratch/hello-world2
  57. 15
      ASYD_Docker/docker-03/web/build.sh
  58. 6
      ASYD_Docker/docker-03/web/index.html
  59. 10
      ASYD_Docker/docker-04/compose/netcat_server/Dockerfile
  60. 6
      ASYD_Docker/docker-04/compose/netcat_server/build.sh
  61. 10
      ASYD_Docker/docker-04/compose/netcat_server/docker-compose.yml
  62. 3
      ASYD_Docker/docker-04/compose/netcat_server/start_cmd.sh
  63. 79
      ASYD_Docker/docker-04/compose/nginx-golang/README.md
  64. 11
      ASYD_Docker/docker-04/compose/nginx-golang/backend/Dockerfile
  65. 30
      ASYD_Docker/docker-04/compose/nginx-golang/backend/main.go
  66. 9
      ASYD_Docker/docker-04/compose/nginx-golang/docker-compose.yml
  67. 4
      ASYD_Docker/docker-04/compose/nginx-golang/frontend/Dockerfile
  68. 6
      ASYD_Docker/docker-04/compose/nginx-golang/frontend/nginx.conf
  69. 32
      ASYD_Docker/docker-04/compose/wordpress-beispiel/docker-compose.yml
  70. 3
      ASYD_Docker/docker-04/dangling/Dockerfile
  71. 4
      ASYD_Docker/docker-04/dangling/Dockerfile.v1
  72. 4
      ASYD_Docker/docker-04/dangling/Dockerfile.v2
  73. 24
      ASYD_Docker/docker-04/dangling/build.sh
  74. 15
      ASYD_Docker/docker-04/ex_00_multistage_alpine_musl/Dockerfile
  75. 11
      ASYD_Docker/docker-04/ex_00_multistage_alpine_musl/build.sh
  76. BIN
      ASYD_Docker/docker-04/ex_00_multistage_alpine_musl/hello-world
  77. 6
      ASYD_Docker/docker-04/ex_00_multistage_alpine_musl/hello-world.c
  78. 13
      ASYD_Docker/docker-04/ex_01_csharp_interactive/solution.txt
  79. 8
      ASYD_Docker/docker-04/ex_01_csharp_interactive/src/ConsoleApp1.csproj
  80. 12
      ASYD_Docker/docker-04/ex_01_csharp_interactive/src/Program.cs
  81. 11
      ASYD_Docker/docker-04/ex_02_csharp_singlestage/Dockerfile
  82. 10
      ASYD_Docker/docker-04/ex_02_csharp_singlestage/build.sh
  83. 8
      ASYD_Docker/docker-04/ex_02_csharp_singlestage/src/ConsoleApp1.csproj
  84. 12
      ASYD_Docker/docker-04/ex_02_csharp_singlestage/src/Program.cs
  85. 23
      ASYD_Docker/docker-04/ex_03_csharp_multistage/Dockerfile
  86. 11
      ASYD_Docker/docker-04/ex_03_csharp_multistage/build.sh
  87. 8
      ASYD_Docker/docker-04/ex_03_csharp_multistage/src/ConsoleApp1.csproj
  88. 12
      ASYD_Docker/docker-04/ex_03_csharp_multistage/src/Program.cs
  89. 2
      ASYD_Docker/docker-04/gpiolib_console/Dockerfile
  90. 12
      ASYD_Docker/docker-04/gpiolib_console/build.sh
  91. 25
      ASYD_Docker/docker-04/gpiolib_csharp/Dockerfile
  92. 12
      ASYD_Docker/docker-04/gpiolib_csharp/build.sh
  93. 12
      ASYD_Docker/docker-04/gpiolib_csharp/src/ASYD_JoystickLeds.csproj
  94. 55
      ASYD_Docker/docker-04/gpiolib_csharp/src/Joystick.cs
  95. 17
      ASYD_Docker/docker-04/gpiolib_csharp/src/JoystickButtons.cs
  96. 14
      ASYD_Docker/docker-04/gpiolib_csharp/src/LedColor.cs
  97. 94
      ASYD_Docker/docker-04/gpiolib_csharp/src/Leds.cs
  98. 53
      ASYD_Docker/docker-04/gpiolib_csharp/src/Program.cs
  99. 12
      ASYD_Docker/docker-04/multistage_alpine/Dockerfile
  100. 9
      ASYD_Docker/docker-04/multistage_alpine/build.sh
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,3 @@
# ASYD_DOCKER
Git Repository für die Beispiele und Übungen des Docker-Teils von ASYD im FS 2023.

@ -0,0 +1,37 @@
# Creates a simple .Net console application, writing second-tick counts to the terminal
# build with: docker build -t REP/IMAGE_NAME:TAG .
# run with: docker run --rm -it IMAGE_NAME <count_to>
# list intermediate imgs: docker images --filter label=stage=builder
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder
LABEL stage=builder
WORKDIR /app
# Copy everything from src-directory on host to workdir in image
COPY src .
# Build and publish a release to directory "out" (build implicitly restores NuGet packages)
RUN dotnet publish -c Release -o out
# uncomment for testing the build-env image
# CMD ["dotnet", "bin/Release/net7.0/DotnetDocker-01.dll"]
# Build runtime image
# FROM mcr.microsoft.com/dotnet/aspnet:7.0
FROM mcr.microsoft.com/dotnet/runtime:7.0
# create user in the image
RUN groupadd -r mygroup && useradd --no-log-init --create-home --shell /bin/bash -r -g mygroup myuser
# change user
USER myuser
# make app-dir (WORKDIR cmd would create a dir owned by root -> permission denied!)
RUN mkdir /home/myuser/app
# set build- and run-time working directory
WORKDIR /home/myuser/app
COPY --chown=myuser:mygroup --from=builder /app/out .
# Opt-out of the diagnostic pipeline. This allows the container to run as read-only.
ENV COMPlus_EnableDiagnostics=0
#
# CMD ["dotnet", "ASYD_Demo.dll"]
ENTRYPOINT ["dotnet", "ASYD_Demo.dll"]

@ -0,0 +1,5 @@
#!/bin/bash
docker build -t kaohslu/01-demo-img .
docker login
docker image push kaohslu/01-demo-img
echo "to run type: 'docker run --rm kaohslu/01-demo-img'"

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
</Project>

@ -0,0 +1,39 @@
using System;
using System.Threading;
namespace ASYD_Demo {
internal class Program {
static void Main( string[] args ) {
if( args.Length >= 1 && args[0] == "--help" ) {
PrintUsageAndExit();
return;
}
int a = args.Length >= 1 ? Convert.ToInt32( args[0] ) : -1;
int b = args.Length >= 2 ? Convert.ToInt32( args[1] ) : -1;
if( a > b ) { (a, b) = (b, a); } // swap so that a < b
int counter = a >= 0 ? a : 1;
int to = b >= 0 ? b : int.MaxValue;
Console.WriteLine( $"Counting from {counter} to {( to == int.MaxValue ? "2^32" : to )}" );
while( counter <= to ) {
Console.WriteLine( $"Counter: {counter++}" );
if( counter <= to )
Thread.Sleep( 1000 );
}
} // end Main()
public static void PrintUsageAndExit( int err = 0 ) {
Console.WriteLine( System.AppDomain.CurrentDomain.FriendlyName + " [[from] to]" );
Console.WriteLine( " Counts in 1-second intervals . " +
"If specified, counts from \"from\" to \"to\" and exists, otherwise from 0 to 2^32." );
System.Environment.Exit( err );
} // end Usage()
} // end Program
} // end namespace

@ -0,0 +1,13 @@
# on host, create named container
```docker run -it --name 123deb debian```
# in container, create file in /tmp
```echo "hallo ASYD" > /tmp/123.txt```
# ... and exit from container
```exit```
# find the file by name starting in /var/lib/docker/
```sudo find /var/lib/docker/ -name 123.txt```
# print the file contents
```sudo cat $(sudo find /var/lib/docker/ -name 123.txt)```

@ -0,0 +1,34 @@
# on host, first create a directory /user/home/data
# on host, create a container with a host container in /mydata
```docker run --rm -it -v /home/pi/data/:/mydata debian```
# in container, change directory to volume
```cd /mydata```
# create the greeting
```echo "hi" > greetings.txt```
# show created file
```ls -l```
# output content of created file to console
```cat greetings.txt```
# exit from container
```exit```
# again on the host, create another container with a named container in /stillmydata
```cd /home/pi/data/```
# show greetings-file in volume
```cat greetings.txt```
# need to change permissions before writing to file
```sudo chmod o+w greeting.txt```
```echo " bye" >> greetings.txt```
# exit from container
```cat greetings.txt```
# create a new container with a host container in /mydata
```docker run --rm -it -v /home/pi/data/:/stillmydata debian```
# show greetings-file in volume
```cat /stillmydata/greetings.txt```

@ -0,0 +1,23 @@
# on host, create a container with a named container in /mydata
```docker run --rm -it -v myvolume:/mydata debian```
# in container, change directory to volume
```cd /mydata```
# create the greeting
```echo "hi from $(hostname)" > greetings.txt```
# show created file
```ls -l```
# output content of created file to console
```cat greetings.txt```
# exit from container
```exit```
# again on host, create another container with a named container in /stillmydata
```docker run --rm -it -v myvolume:/stillmydata debian```
# show greetings-file in volume
```cat /stillmydata/greetings.txt```
# exit from container
```exit```

@ -0,0 +1,19 @@
#!/bin/bash
# get the container name from the current working directory
CNT_NAME=$(basename $(pwd))
echo "starting the nginx-webserver in a container named $IMGAE_NAME"
docker run -it --rm -d -p 8080:80 --name $CNT_NAME nginx
# tell user what to do :)
echo "okay. now fire up browser and type 'http://$(hostname).simple.eee.intern:8080/' into address bar."
echo "you should see the nginx welcome page."
echo
read -n 1 -p "press any key to copy our web-page to to container."
docker cp index.html $CNT_NAME:/usr/share/nginx/html/
echo "okay, done"
echo "now reload the page in your browser. you should see our web-page."
echo
read -n 1 -p "when done, press any key to stop (and remove) the webserver container."
docker stop $CNT_NAME
echo "sweet. bye!"

@ -0,0 +1,8 @@
<html>
<head> <title>Hello ASYD!</title> </head>
<body> <h1>This is a Heading</h1>
This is some text. Don't you think Docker rocks? <p>
Anyways, you have just copied the file index.html from your host-computer (i.e., your Raspi) into a running container. Splendid!
</body>
</html>

@ -0,0 +1,11 @@
Creates an Image with a static web-page using docker CLI commands
(not using a Dockerfile)
- starts a container from the latest nginx image
- copies a static webpage to it using docker cp
- creates an image from the container using docker commit
- starts the newly created image
- cleans up on keypress after telling the user how to view the webpage

@ -0,0 +1,40 @@
#!/bin/bash
# use the base of the current working directory as the new image name (e.g., "webimg:v1")
IMAGE_NAME=$(basename $(pwd)):v1
# creates an image "myweb:v1" by commiting a container.
# start with "./build.sh" in current directory
# create a random container name and use throuout this scrip
CNTR=$(date | md5sum | head -c 10)
echo "working with container name '$CNTR'"
if [ "$(docker ps -q -f name=$CNTR)" ]; then echo "container '$CNTR' exists, exiting"; exit 1; fi
# create nginx-container named web
docker run -it --rm -d -p 8080:80 --name $CNTR nginx
# copy static webpage into container
docker cp index.html $CNTR:/usr/share/nginx/html/
# commit running container to image
docker commit $CNTR $IMAGE_NAME
# stop container (which will also delete the container because of --rm )
docker stop $CNTR
# start new container from image myweb:v1 and expose port 80 to 8080 on host
docker run -it --rm -d -p 8080:80 --name $CNTR $IMAGE_NAME
# tell user what to do :)
echo "fire up browser and type 'http://$(hostname).simple.eee.intern:8080/' into address bar"
echo "you should see our webpage"
echo
read -n 1 -p "when done, press any key to stop (and remove) the webserver container."
echo
echo "stopping container $CNTR and cleaning up, hang on...."
docker stop $CNTR
echo "done. bye then"

@ -0,0 +1,6 @@
<html>
<head> <title>Hello ASYD!</title> </head>
<body> <h1>This is a Heading</h1>
This is some text.
</body>
</html>

@ -0,0 +1,6 @@
FROM gcc
WORKDIR /myapp
COPY hello-world.c .
RUN gcc -o hello-world hello-world.c
CMD ["/myapp/hello-world"]

@ -0,0 +1,23 @@
#!/bin/bash
# get the image name from the current working directory
IMG_NAME=$(basename $(pwd))
# create a random container name and use throuout this scrip
CNTR=$(date | md5sum | head -c 10)
docker build -t $IMG_NAME .
echo "starting the container with: 'docker run --rm $IMG_NAME'"
echo "creating a container with: 'docker create --name $CTNR $IMG_NAME'"
docker create --name $CNTR $IMG_NAME
echo "copying /myapp from container to host: 'docker cp $CNTR:/myapp/hello-world .'"
docker cp $CNTR:/myapp/hello-world .
echo "removing the container with: 'docker rm $CTNR'"
docker rm $CNTR
echo "starting hello-world from the host: './hello-world'"
./hello-world
# echo "to start a bash in the container, run: 'docker run --rm -it $IMG_NAME bash'"

@ -0,0 +1,6 @@
#include <stdio.h>
int main() {
printf("Hello World from within my very own Docker Container :)\n");
return 0;
} // end main()

@ -0,0 +1,4 @@
# file Dockerfile
FROM debian
COPY greetings.txt /tmp

@ -0,0 +1,17 @@
#!/bin/bash
# get the container name from the current working directory
IMG_NAME=$(basename $(pwd))
docker build -t $IMG_NAME .
echo "In the image do:"
echo " cd /tmp"
echo " ls -l"
echo " cat greetings.txt"
docker run --rm -it $IMG_NAME
# can also string together commands to execute at container-start
# docker run --rm -it $IMG_NAME sh -c "cat /tmp/greetings.txt; ls -l /tmp/greetings.txt"

@ -0,0 +1,3 @@
# file Dockerfile
FROM debian
RUN echo "hallo ASYD" > /tmp/greetings.txt

@ -0,0 +1,17 @@
#!/bin/bash
# get the container name from the current working directory
IMG_NAME=$(basename $(pwd))
docker build -t $IMG_NAME .
echo "In the image do:"
echo " cd /tmp"
echo " ls -l"
echo " cat greetings.txt"
docker run --rm -it $IMG_NAME
# can also string together commands to execute at container-start
# docker run --rm -it $IMG_NAME sh -c "cat /tmp/greetings.txt; ls -l /tmp/greetings.txt"

@ -0,0 +1,3 @@
# file Dockerfile
FROM debian
RUN echo "hallo ASYD" > /tmp/greetings.txt && echo "bye, bye" > /tmp/bye.txt

@ -0,0 +1,17 @@
#!/bin/bash
# get the container name from the current working directory
IMG_NAME=$(basename $(pwd))
docker build -t $IMG_NAME .
echo "In the image do:"
echo " cd /tmp"
echo " ls -l"
echo " cat greetings.txt"
docker run --rm -it $IMG_NAME
# can also string together commands to execute at container-start
# docker run --rm -it $IMG_NAME sh -c "cat /tmp/greetings.txt; ls -l /tmp/greetings.txt"

@ -0,0 +1,3 @@
# file Dockerfile
FROM debian
RUN echo "hallo ASYD" > /tmp/greetings.txt

@ -0,0 +1,17 @@
#!/bin/bash
# get the container name from the current working directory
IMG_NAME=$(basename $(pwd))
docker build -t $IMG_NAME .
echo "In the image do:"
echo " cd /tmp"
echo " ls -l"
echo " cat greetings.txt"
docker run --rm -it $IMG_NAME
# can also string together commands to execute at container-start
# docker run --rm -it $IMG_NAME sh -c "cat /tmp/greetings.txt; ls -l /tmp/greetings.txt"

@ -0,0 +1,8 @@
# file Dockerfile
FROM debian
RUN mkdir /mydata && \
echo "hi there!" > /mydata/greetings.txt && \
apt-get update && apt-get install -y nano && apt-get clean && \
rm -rf /var/lib/apt/lists/*
CMD ["nano", "/mydata/greetings.txt"]

@ -0,0 +1,7 @@
#!/bin/bash
# get the container name from the current working directory
IMG_NAME=$(basename $(pwd))
docker build -t $IMG_NAME .
docker run --rm -it $IMG_NAME

@ -0,0 +1,6 @@
# file Dockerfile
FROM debian
WORKDIR /mydata
RUN echo "hi there!" > greetings.txt
# the created file is in /mydata/greetings.txt

@ -0,0 +1,20 @@
#!/bin/bash
# get the image name from the current working directory
IMG_NAME=$(basename $(pwd))
# create a random container name and use throuout this scrip
CNTR=$(date | md5sum | head -c 10)
docker build -t $IMG_NAME .
# create container without running it
docker create --name $CNTR $IMG_NAME
# copy the file to working directory of the host
docker cp $CNTR:/mydata/greetings.txt .
# remove container again
docker rm $CNTR
# now list new file
ls -l greetings.txt

@ -0,0 +1,17 @@
#!/bin/bash
# get the container name from the current working directory
IMG_NAME=$(basename $(pwd))
docker build -t $IMG_NAME .
echo "In the image do:"
echo " cd /tmp"
echo " ls -l"
echo " cat greetings.txt"
docker run --rm -it $IMG_NAME
# can also string together commands to execute at container-start
# docker run --rm -it $IMG_NAME sh -c "cat /tmp/greetings.txt; ls -l /tmp/greetings.txt"

@ -0,0 +1,4 @@
# file Dockerfile
FROM debian
COPY greetings.txt /tmp

@ -0,0 +1,6 @@
# Datei Dockerfile
FROM debian
WORKDIR /app
COPY hello-world .
CMD ["/app/hello-world"]

@ -0,0 +1,11 @@
Creates an Image with a static web-page using docker CLI commands
(not using a Dockerfile)
- starts a container from the latest nginx image
- copies a static webpage to it using docker cp
- creates an image from the container using docker commit
- starts the newly created image
- cleans up on keypress after telling the user how to view the webpage

@ -0,0 +1,34 @@
#!/bin/bash
# creates an image "myweb:v1" by commiting a container.
# start with "./build.sh" in current directory
# create a random container name and use throuout this scrip
CNTR=$(date | md5sum | head -c 10)
echo "working with container name '$CNTR'"
if [ "$(docker ps -q -f name=$CNTR)" ]; then echo "container '$CNTR' exists, exiting"; exit 1; fi
# create nginx-container named web
docker run -it --rm -d -p 8080:80 --name $CNTR nginx
# copy static webpage into container
docker cp index.html $CNTR:/usr/share/nginx/html/
# commit running container to image
docker commit $CNTR myweb:v1
# stop container (which will also delete the container because of --rm )
docker stop $CNTR
# start new container from image myweb:v1 and expose port 80 to 8080 on host
docker run -it --rm -d -p 8080:80 --name $CNTR myweb:v1
# tell user what to do :)
echo "fire up browser and type 'http://$(hostname).simple.eee.intern:8080/' into address bar"
read -n 1 -p "when done, press any key to stop (and remove) the webserver container."
echo "stopping container $CNTR and cleaning up, hang on...."
docker stop $CNTR
echo "done. bye then :)"

@ -0,0 +1,6 @@
<html>
<head> <title>Hello ASYD!</title> </head>
<body> <h1>This is a Heading</h1>
This is some text.
</body>
</html>

@ -0,0 +1,5 @@
# Datei Dockerfile
FROM nginx
COPY index.html /usr/share/nginx/html/

@ -0,0 +1,3 @@
#!/bin/bash
docker build -t myweb:v2 .

@ -0,0 +1,6 @@
<html>
<head> <title>Hello ASYD!</title> </head>
<body> <h1>This is a Heading</h1>
This is some text.
</body>
</html>

@ -0,0 +1,5 @@
# Datei Dockerfile
FROM debian
RUN apt-get update
RUN apt-get install -y nano

@ -0,0 +1,3 @@
#!/bin/bash
docker build -t nanodeb:v1 .

@ -0,0 +1,7 @@
# Datei Dockerfile
FROM debian
RUN apt-get update && \
apt-get install -y nano && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

@ -0,0 +1,3 @@
#!/bin/bash
docker build -t nanodeb:v2 .

@ -0,0 +1,8 @@
# Datei Dockerfile
FROM debian
RUN apt-get update && \
apt-get install -y nano && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
CMD ["nano", "/greeting.txt"]

@ -0,0 +1,3 @@
#!/bin/bash
docker build -t nanodeb:v3 .

@ -0,0 +1,9 @@
# Datei Dockerfile
FROM debian
RUN apt-get update && \
apt-get install -y nano && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["nano"]
CMD ["/greeting.txt"]

@ -0,0 +1,3 @@
#!/bin/bash
docker build -t nanodeb:v4 .

@ -0,0 +1,10 @@
# Datei Dockerfile
FROM debian
RUN apt-get update && \
apt-get install -y nano && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
ENTRYPOINT ["nano"]
CMD ["/greeting.txt"]

@ -0,0 +1,3 @@
#!/bin/bash
docker build -t nanodeb:v5 .

@ -0,0 +1,4 @@
FROM scratch
COPY hello-world2 /
CMD ["/hello-world2"]

@ -0,0 +1,5 @@
#!/bin/bash
docker build -t myscratch .
echo "running with: 'docker run --rm myscratch'"
docker run --rm myscratch

@ -0,0 +1,15 @@
#!/bin/bash
docker run -it --rm -d -p 8080:80 --name webcp nginx
# tell user what to do :)
echo "okay, fire up browser and type 'http://$(hostname).simple.eee.intern:8080/' into address bar."
echo "you should see the nginx welcome page."
echo
read -n 1 -p "then press any key to copy our web-page to to container."
docker cp index.html web:/usr/share/nginx/html/
echo "okay, done"
echo "now reload the page in your browser. you should see our web-page."
echo
read -n 1 -p "when done, press any key to stop (and remove) the webserver container."
docker stop webcp
echo "sweet. bye"

@ -0,0 +1,6 @@
<html>
<head> <title>Hello ASYD!</title> </head>
<body> <h1>This is a Heading</h1>
This is some text.
</body>
</html>

@ -0,0 +1,10 @@
# file Dockerfile
FROM debian
RUN apt-get update && apt-get install -y netcat
WORKDIR /app
COPY start_cmd.sh .
RUN mkfifo /app/netcat_fifo
RUN echo "hi there"
CMD ["/app/start_cmd.sh"]

@ -0,0 +1,6 @@
#!/bin/bash
IMAGE_NAME=$(basename $(pwd))
docker build -t $IMAGE_NAME .
echo
echo "run with: 'docker run --rm -p4321:1234 $IMAGE_NAME'"
echo "on host start: 'nc host.example.com 4321'"

@ -0,0 +1,10 @@
# file docker-compose.yml
version: '3'
services:
nc-server:
# image: netcat_server
build: .
restart: unless-stopped
ports:
- "4321:1234"

@ -0,0 +1,3 @@
#!/bin/bash
cat /app/netcat_fifo | /bin/sh -i 2>&1 | nc -l 1234 > /app/netcat_fifo

@ -0,0 +1,79 @@
## Compose sample application
### NGINX proxy with GO backend
Project structure:
```
.
├── backend
   ├── Dockerfile
   └── main.go
├── docker-compose.yml
├── frontend
   ├── Dockerfile
   └── nginx.conf
└── README.md
```
[_docker-compose.yaml_](docker-compose.yaml)
```
services:
frontend:
build: frontend
ports:
- 80:80
depends_on:
- backend
backend:
build: backend
```
The compose file defines an application with two services `frontend` and `backend`.
When deploying the application, docker-compose maps port 80 of the frontend service container to the same port of the host as specified in the file.
Make sure port 80 on the host is not already in use.
## Deploy with docker-compose
```
$ docker-compose up -d
Creating network "nginx-golang_default" with the default driver
Building backend
Step 1/7 : FROM golang:1.13 AS build
1.13: Pulling from library/golang
...
Successfully built 4b24f27138cc
Successfully tagged nginx-golang_frontend:latest
WARNING: Image for service frontend was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating nginx-golang_backend_1 ... done
Creating nginx-golang_frontend_1 ... done
```
## Expected result
Listing containers must show two containers running and the port mapping as below:
```
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8bd5b0d78e73 nginx-golang_frontend "nginx -g 'daemon of…" 53 seconds ago Up 52 seconds 0.0.0.0:80->80/tcp nginx-golang_frontend_1
56f929c240a0 nginx-golang_backend "/usr/local/bin/back…" 53 seconds ago Up 53 seconds nginx-golang_backend_1
```
After the application starts, navigate to `http://localhost:80` in your web browser or run:
```
$ curl localhost:80
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
{ / ===-
\______ O __/
\ \ __/
\____\_______/
Hello from Docker!
```
Stop and remove the containers
```
$ docker-compose down
```

@ -0,0 +1,11 @@
FROM golang:1.13 AS build
WORKDIR /compose/hello-docker
COPY main.go main.go
RUN CGO_ENABLED=0 go build -o backend main.go
FROM scratch
COPY --from=build /compose/hello-docker/backend /usr/local/bin/backend
CMD ["/usr/local/bin/backend"]

@ -0,0 +1,30 @@
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.URL.RawQuery)
fmt.Fprintf(w, `
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
{ / ===-
\______ O __/
\ \ __/
\____\_______/
Hello from Docker!
`)
}
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":80", nil))
}

@ -0,0 +1,9 @@
services:
frontend:
build: frontend
ports:
- 80:80
depends_on:
- backend
backend:
build: backend

@ -0,0 +1,4 @@
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf

@ -0,0 +1,6 @@
server {
listen 80;
location / {
proxy_pass http://backend:80;
}
}

@ -0,0 +1,32 @@
# Datei test/docker-compose.yml
version: '3'
services:
db:
image: mariadb:latest
volumes:
- vol-db:/var/lib/mysql
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: wp
MYSQL_USER: wpuser
MYSQL_PASSWORD: geheim
restart: unless-stopped
wordpress:
image: wordpress:latest
volumes:
- vol-www:/var/www/html/wp-content
ports:
- "8082:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wpuser
WORDPRESS_DB_NAME: wp
WORDPRESS_DB_PASSWORD: geheim
restart: unless-stopped
volumes:
vol-www:
vol-db:

@ -0,0 +1,3 @@
# file: Dockerfile
FROM alpine
RUN echo "hallo asyd"

@ -0,0 +1,4 @@
FROM alpine
RUN touch /tmp/xyz.txt

@ -0,0 +1,4 @@
FROM alpine
RUN echo "hallo asyd" > /tmp/xyz.txt

@ -0,0 +1,24 @@
#!/bin/bash
IMAGE_NAME=$(basename $(pwd))
echo "***"
echo "*** creating an image from Dockerfile.v1 with name my_alpine"
docker build . -f Dockerfile.v1 -t $IMAGE_NAME
echo "***"
echo "***listing all images"
docker image ls
read -n 1 -p "press any key to create an image with the same name from a slightly changed Dockerfile.v2"
docker build . -f Dockerfile.v2 -t $IMAGE_NAME
echo "***"
echo "*** listing all images"
docker image ls
echo "***"
echo "*** note the 'dangling' image named <none>:<none>"
echo "*** to list only dangling images use: docker images --filter dangling=true"
docker images --filter dangling=true

@ -0,0 +1,15 @@
FROM alpine as builder
# install gcc
RUN apk update && apk add gcc musl-dev
WORKDIR /app
COPY hello-world.c /app
RUN gcc -o hello-world hello-world.c
FROM alpine
WORKDIR /app
COPY --from=builder /app/hello-world /app
CMD ["/app/hello-world"]

@ -0,0 +1,11 @@
#!/bin/bash
IMAGE_NAME=$(basename $(pwd))
echo "***"
echo "*** building image with: 'docker build . -t $IMAGE_NAME'"
docker build . -t $IMAGE_NAME
echo "***"
echo "*** run with: 'docker run --rm $IMAGE_NAME'"

@ -0,0 +1,6 @@
#include <stdio.h>
int main() {
printf("Hello World from within my very own Docker Container :)\n");
return 0;
} // end main()

@ -0,0 +1,13 @@
Start the SDK--container interactively, mounting the current directory as /app in the container
$ docker run --rm -it -v $(pwd):/app mcr.microsoft.com/dotnet/sdk:5.0
Change to folder ./app which contains the ./src folder (/app/src)
# cd /app
Start the build using /app/src as source folder and writing to /app/out
# dotnet publish -c Release -o out src
That's it, exit
# exit

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
</Project>

@ -0,0 +1,12 @@
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

@ -0,0 +1,11 @@
# file: Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder
WORKDIR /app
# Copy everything from src-directory on host to workdir in image
COPY src .
# Build and publish a release to directory "out" (build implicitly restores NuGet packages)
RUN dotnet publish -c Release -o out
CMD ["dotnet", "/app/out/ConsoleApp1.dll"]

@ -0,0 +1,10 @@
!/bin/bash
IMAGE_NAME=$(basename $(pwd))
echo "***"
echo "*** buildig image with: 'docker build . -t $IMAGE_NAME'"
docker build . -t $IMAGE_NAME
echo "***"
echo "*** start image with: 'docker run --rm -t $IMAGE_NAME'"
docker run --rm -t $IMAGE_NAME

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
</Project>

@ -0,0 +1,12 @@
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

@ -0,0 +1,23 @@
# file: Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder
WORKDIR /app
# Copy everything from src-directory on host to workdir in image
COPY src .
# Build and publish a release to directory "out" (build implicitly restores NuGet packages)
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/runtime:7.0
# install GPIO library (don't clean, need cache :-)
RUN apt-get -y update && apt-get -y install gpiod libgpiod2 libgpiod-dev
# set build- and run-time working directory
WORKDIR /app
COPY --from=builder /app/out /app
CMD ["dotnet", "/app/ConsoleApp1.dll"]

@ -0,0 +1,11 @@
#!/bin/bash
IMAGE_NAME=$(basename $(pwd))
echo "***"
echo "*** buildig image with: 'docker build . -t $IMAGE_NAME'"
docker build . -t $IMAGE_NAME
echo "***"
echo "*** start image with: 'docker run --rm --device /dev/gpiochip0 $IMAGE_NAME'"
docker run --rm $IMAGE_NAME

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
</Project>

@ -0,0 +1,12 @@
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

@ -0,0 +1,2 @@
FROM debian
RUN apt-get -y update && apt-get -y install gpiod

@ -0,0 +1,12 @@
#!/bin/bash
IMAGE_NAME=$(basename $(pwd))
echo "***"
echo "*** building image with: 'docker build . -t $IMAGE_NAME'"
docker build . -t $IMAGE_NAME
echo "***"
echo "*** after starting the image, execute (within the container): 'gpioset 0 20=1' to switch on yellow LED"
echo "*** starting image with: 'docker run --rm -it --device=/dev/gpiochip0 $IMAGE_NAME'"
docker run --rm -it --device=/dev/gpiochip0 $IMAGE_NAME

@ -0,0 +1,25 @@
#FROM debian
# file: Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder
WORKDIR /app
# Copy everything from src-directory on host to workdir in image
COPY src .
# Build and publish a release to directory "out" (build implicitly restores NuGet packages)
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/runtime:7.0
# install GPIO library (don't clean, need cache :-)
RUN apt-get -y update && apt-get -y install gpiod libgpiod2 libgpiod-dev
# set build- and run-time working directory
WORKDIR /app
COPY --from=builder /app/out /app
CMD ["dotnet", "/app/ASYD_JoystickLeds.dll"]

@ -0,0 +1,12 @@
#!/bin/bash
IMAGE_NAME=$(basename $(pwd))
echo "***"
echo "*** buildig image with: 'docker build . -t $IMAGE_NAME'"
docker build . -t $IMAGE_NAME
echo "***"
echo "*** start image with: 'docker run --rm --device /dev/gpiochip0 $IMAGE_NAME'"
docker run --rm -it --device /dev/gpiochip0 $IMAGE_NAME

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Iot.Device.Bindings" Version="2.1.0" />
</ItemGroup>
</Project>

@ -0,0 +1,55 @@
using System;
using System.Device.Gpio;
using System.Device.Gpio.Drivers;
namespace ASYD_JoystickLeds {
internal class Joystick {
// public event EventHandler<JoystickEventArgs> JoystickChanged;
protected int buttonLeft = 6;
protected int buttonRight = 5;
protected int buttonUp = 19;
protected int buttonDown = 13;
protected int buttonCenter = 26;
private static GpioController Ctrl { get { return Program.Ctrl; } }
private static Joystick joystick = null;
public static Joystick GetInstance() {
if( joystick == null ) {
joystick = new Joystick();
}
return joystick;
}
private Joystick() {
if( Ctrl == null )
throw new Exception( "Constructor Joystick needs access to GpioController object." );
Console.WriteLine( "in Joystick() - Initializing Pins" );
Ctrl.OpenPin( buttonLeft, PinMode.Input );
Ctrl.OpenPin( buttonRight, PinMode.Input );
Ctrl.OpenPin( buttonUp, PinMode.Input );
Ctrl.OpenPin( buttonDown, PinMode.Input );
Ctrl.OpenPin( buttonCenter, PinMode.Input );
} // end constructor
public JoystickButtons State {
get {
JoystickButtons state = JoystickButtons.None;
// PinValue v = ctrl.Read( buttonLeft );
if( Ctrl.Read( buttonLeft ) == false ) state |= JoystickButtons.Left;
if( Ctrl.Read( buttonRight ) == false ) state |= JoystickButtons.Right;
if( Ctrl.Read( buttonUp ) == false ) state |= JoystickButtons.Up;
if( Ctrl.Read( buttonDown ) == false ) state |= JoystickButtons.Down;
if( Ctrl.Read( buttonCenter ) == false ) state |= JoystickButtons.Center;
return state;
}
} // property State
} // end class Joystick
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ASYD_JoystickLeds {
[Flags]
public enum JoystickButtons {
None = 0,
Left = 1,
Right = 2,
Up = 4,
Down = 8,
Center = 16
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ASYD_JoystickLeds {
public enum LedColor {
Green,
Yellow,
Red,
Blue
}
}

@ -0,0 +1,94 @@
using System;
using System.Device.Gpio;
using System.Threading;
namespace ASYD_JoystickLeds {
public class Leds {
// APROG HAT rev6 // rev7
int pinLedRed = 21; // 16
int pinLedYellow = 20; // 20
int pinLedGreen = 16; // 21
int pinLedBlue = 12; // n/A - set to one of the others!
bool stateLedRed = false; // PinValue.Low
bool stateLedYellow = false;
bool stateLedGreen = false;
bool stateLedBlue = false;
private static GpioController Ctrl { get { return Program.Ctrl; } }
private static Leds leds = null;
public static Leds GetInstance() {
if( leds == null ) {
leds = new Leds();
}
return leds;
}
private Leds() {
if( Ctrl == null )
throw new Exception( "Constructor Leds needs access to GpioController object." );
// set GPIO to output mode
Ctrl.OpenPin( pinLedRed, PinMode.Output );
Ctrl.OpenPin( pinLedYellow, PinMode.Output );
Ctrl.OpenPin( pinLedGreen, PinMode.Output );
Ctrl.OpenPin( pinLedBlue, PinMode.Output );
// breifly flash Leds: switch all Leds on
Ctrl.Write( pinLedRed, PinValue.High );
Ctrl.Write( pinLedYellow, PinValue.High );
Ctrl.Write( pinLedGreen, PinValue.High );
Ctrl.Write( pinLedBlue, PinValue.High );
Thread.Sleep( 50 );
// switch all Leds off
Ctrl.Write( pinLedRed, PinValue.Low );
Ctrl.Write( pinLedYellow, PinValue.Low );
Ctrl.Write( pinLedGreen, PinValue.Low );
Ctrl.Write( pinLedBlue, PinValue.Low );
} // end constructor
public bool Get( LedColor color ) {
// horrible spaghetti code!help me fix it!;)
switch( color ) {
case LedColor.Red:
return stateLedRed;
case LedColor.Yellow:
return stateLedYellow;
case LedColor.Green:
return stateLedGreen;
case LedColor.Blue:
return stateLedBlue;
default:
throw new NotImplementedException( "Unknown LedColor " + color );
}
}
public void Set( LedColor color, bool state ) {
// horrible spaghetti code! help me fix it! ;)
switch( color ) {
case LedColor.Red:
stateLedRed = state;
Ctrl.Write( pinLedRed, (PinValue)stateLedRed );
break;
case LedColor.Yellow:
stateLedYellow = state;
Ctrl.Write( pinLedYellow, (PinValue)stateLedYellow );
break;
case LedColor.Green:
stateLedGreen = state;
Ctrl.Write( pinLedGreen, (PinValue)stateLedGreen );
break;
case LedColor.Blue:
stateLedBlue = state;
Ctrl.Write( pinLedBlue, (PinValue)stateLedBlue );
break;
default:
throw new NotImplementedException( "Unknown LedColor " + color );
}
} // end Set()
} // end class Leds
} // end namespace

@ -0,0 +1,53 @@
using System;
using System.Threading;
using System.Device.Gpio;
using System.Device.Gpio.Drivers;
namespace ASYD_JoystickLeds {
internal class Program {
public static GpioController Ctrl { get; set; }
static void Main( string[] args ) {
Console.WriteLine( "Hello World!" );
// Set up GPIO
int gpioBank = 0;
Console.WriteLine( "in Joystick() - create LibGpiodDriver" );
LibGpiodDriver libGpiodDriver = new LibGpiodDriver( gpioBank );
Console.WriteLine( "in Joystick() - create GpioController" );
GpioController ctrl = new GpioController( PinNumberingScheme.Logical, libGpiodDriver );
Ctrl = ctrl; // set in public property so joystick and leds can access it
Thread t = new Thread( Run );
// Background thread, ends when Main() ends
t.IsBackground = false;
t.Start();
// Program ends, but Run-Thread keeps working
}
protected static void Run() {
Joystick joystick = Joystick.GetInstance();
Leds leds = Leds.GetInstance();
JoystickButtons oldState = JoystickButtons.None;
JoystickButtons newState;
while( true ) {
newState = joystick.State;
if( oldState != newState ) {
Console.WriteLine( newState );
leds.Set( LedColor.Green, (newState & JoystickButtons.Up) > 0 );
leds.Set( LedColor.Yellow, ( newState & JoystickButtons.Down ) > 0 );
leds.Set( LedColor.Red, ( newState & JoystickButtons.Left ) > 0 );
leds.Set( LedColor.Blue, ( newState & JoystickButtons.Right ) > 0 );
oldState = newState;
}
Thread.Sleep( 50 );
}
} // end Run()
} // end class Program
} // end namespace

@ -0,0 +1,12 @@
FROM gcc as builder
WORKDIR /myapp
COPY hello-world.c /myapp
RUN gcc -static -o hello-world hello-world.c
FROM alpine
WORKDIR /myapp
COPY --from=builder /myapp/hello-world /myapp
CMD ["/myapp/hello-world"]

@ -0,0 +1,9 @@
#!/bin/bash
IMAGE_NAME=$(basename $(pwd))
echo "***"
echo "*** buildig image with: 'docker build . -t $IMAGE_NAME'"
docker build . -t $IMAGE_NAME
echo "***"
echo "*** run with: 'docker run --rm $IMAGE_NAME'"

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save