K8s Applications mit MicroK8S auf Raspberry PI. Alfred Sabitzer
Чтение книги онлайн.

Читать онлайн книгу K8s Applications mit MicroK8S auf Raspberry PI - Alfred Sabitzer страница 12

Название: K8s Applications mit MicroK8S auf Raspberry PI

Автор: Alfred Sabitzer

Издательство: Bookwire

Жанр: Математика

Серия:

isbn: 9783742770134

isbn:

СКАЧАТЬ

      Dann kann man das go Programm testen und builden.

      alfred@monitoring:~$ mkdir go

      alfred@monitoring:~$ cd go

      alfred@monitoring:~/go$ nano hello-world.go

      alfred@monitoring:~/go$ go run hello-world.go

      hello world

      alfred@monitoring:~/go$ go build hello-world.go

      alfred@monitoring:~/go$ ls -lisa

      total 1936

      4688691 4 drwxrwxr-x 2 alfred alfred 4096 Sep 30 11:26 .

      1140881 4 drwxr-xr-x 21 alfred alfred 4096 Sep 30 11:25 ..

       127267 1924 -rwxrwxr-x 1 alfred alfred 2097605 Sep 30 11:26 hello-world

      4688693 4 -rw-rw-r-- 1 alfred alfred 75 Sep 30 11:25 hello-world.go

      alfred@monitoring:~/go$ ./hello-world

      hello world

      alfred@monitoring:~/go$

      Jetzt haben wir das go-Programm, und müssen es in einen Docker-Container packen.

      alfred@monitoring:~/go$ docker rmi $(docker images -q) # Löscht alle vorhandenen Images im lokalen Repository

      Um einen Container zu erzeugen, brauchen wir ein dockerfile.

      alfred@monitoring:~/dev/hello-world$ cat dockerfile

      # syntax=docker/dockerfile:1

      # Alpine is chosen for its small footprint

      # compared to Ubuntu

      FROM golang:1.16-alpine

      WORKDIR /app

      LABEL maintainer="[email protected]"

      COPY go.mod ./

      COPY *.go ./

      RUN go build -o /hallo

      EXPOSE 80

      CMD ["/hallo"]

      alfred@monitoring:~/dev/hello-world$

      Nun bauen wir den Container.

      alfred@monitoring:~/dev/hello-world$ docker build . -t docker.registry:5000/hello-world:20211003

      Sending build context to Docker daemon 9.216kB

      Step 1/8 : FROM golang:1.16-alpine

      1.16-alpine: Pulling from library/golang

      be307f383ecc: Already exists

      e31131f141ae: Pull complete

      7f3ae2225eeb: Pull complete

      27b4cf6759f9: Pull complete

      05c56ed0aaf5: Pull complete

      Digest: sha256:45412fe3f5016509fc448b83faefc34e6f9e9bcc8ca1db1c54505d5528264e16

      Status: Downloaded newer image for golang:1.16-alpine

       ---> bebfc96a903d

      Step 2/8 : WORKDIR /app

       ---> Running in c81df142320d

      Removing intermediate container c81df142320d

       ---> a81936939cb7

      Step 3/8 : LABEL maintainer="[email protected]"

       ---> Running in 88c7acfdf90e

      Removing intermediate container 88c7acfdf90e

       ---> b023746a02d8

      Step 4/8 : COPY go.mod ./

       ---> 599501f1547a

      Step 5/8 : COPY *.go ./

       ---> 9f60a66c2ac0

      Step 6/8 : RUN go build -o /hallo

       ---> Running in 03fd6b04a839

      Removing intermediate container 03fd6b04a839

       ---> e62606c61d94

      Step 7/8 : EXPOSE 80

       ---> Running in 2b3562abb146

      Removing intermediate container 2b3562abb146

       ---> 121727752180

      Step 8/8 : CMD ["hallo"]

       ---> Running in cfa9e78598dc

      Removing intermediate container cfa9e78598dc

       ---> 52dfdc427a61

      Successfully built 52dfdc427a61

      Successfully tagged docker.registry:5000/hello-world:20211003

      alfred@monitoring:~/dev/hello-world$

      Anzeige im lokalen Repository.

      alfred@monitoring:~/go$ docker images

      REPOSITORY TAG IMAGE ID CREATED SIZE

      docker.registry:5000/hello-world 20211003 ebe5a2422dca 24 seconds ago 2.1MB

      alfred@monitoring:~/go$

      Wir können den Inhalt untersuchen, indem wir den Docker in ein Tar-File exportieren.

      alfred@monitoring:~/go$ docker ps -lq

      fc63f4826cff

      alfred@monitoring:~/go$

      alfred@monitoring:~/go$ mkdir test

      alfred@monitoring:~/go$ docker export fc63f4826cff > ./test/hello-world.tar

      alfred@monitoring:~/go$ cd test/

      alfred@monitoring:~/go/test$ tar -xf hello-world.tar

      alfred@monitoring:~/go/test$ ll

      total 4132

      drwxrwxr-x 6 alfred alfred 4096 Oct 3 09:37 ./

      drwxrwxr-x 4 alfred alfred 4096 Oct 3 09:37 ../

      -rwxr-xr-x 1 alfred alfred 0 Oct 3 09:32 .dockerenv*

СКАЧАТЬ