dockerized java workshop for gr8conf 2017
TRANSCRIPT
![Page 1: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/1.jpg)
01
![Page 2: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/2.jpg)
02
![Page 3: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/3.jpg)
Let's start!03
![Page 4: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/4.jpg)
Dockerrrr04
![Page 5: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/5.jpg)
Concepts05
![Page 6: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/6.jpg)
Java's promise
06
![Page 7: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/7.jpg)
Docker's promise
07
![Page 8: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/8.jpg)
Docker engineDocker is a simple client/server application
A Docker Client talks to Docker daemon, which controls images and
containers
Docker Daemon exposes RESTFul API, that can be used remotely
••
•
08
![Page 9: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/9.jpg)
Docker imageReadonly file system image and metadata, that serves as a template
for starting Docker containers.“09
![Page 10: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/10.jpg)
Docker image
10
![Page 11: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/11.jpg)
Dockerfile
11
![Page 12: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/12.jpg)
Docker containerSingle process running within environment created from Docker image“12
![Page 13: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/13.jpg)
Container states
13
![Page 14: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/14.jpg)
Docker volumeA directory shared between the host system and one or more
containers.“14
![Page 15: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/15.jpg)
Docker registryA repository of Docker images
Registry can be private or public
Docker Hub is a public Docker registry
•••
15
![Page 16: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/16.jpg)
Image/container manipulations
16
![Page 17: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/17.jpg)
Docker Flow
17
![Page 18: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/18.jpg)
Container packaging
18
![Page 19: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/19.jpg)
Container packaging
19
![Page 20: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/20.jpg)
Container packaging
20
![Page 21: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/21.jpg)
Let's practice!21
![Page 22: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/22.jpg)
There are many exercises:Use java/javac without installing it (inside Docker container)
Play with simple client/server setup
Build and execute PetClinic application inside a container
Use Maven Docker container to isolate build and run of PetClinic
Run database in a container for PetClinic application
1.
2.
3.
4.
5.
22
![Page 23: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/23.jpg)
Sharing is caring!Gist: http://bit.ly/DOCKER_JAVA_GR8CONF_GIST
Slides: http://bit.ly/DOCKER_JAVA_GR8CONF_SLIDES••
23
![Page 24: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/24.jpg)
Preparation
24
![Page 25: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/25.jpg)
Exercise 1.125
![Page 26: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/26.jpg)
Exercise 1.1: pull java imagesPull Java image without installing Java using: docker pull java
Pull OpenJDK image: docker pull openjdk .
Pull image with tag: docker pull openjdk:latest
Pull different version of Java: docker pull openjdk:7
List local images: docker images
Remove old image: docker rmi openjdk:7
••••••
26
![Page 27: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/27.jpg)
Exercise 1.227
![Page 28: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/28.jpg)
Exercise 1.2: run java/javacLet's check Java version: docker run java java ‐version
Is there any container running: docker ps ?
Are there any traces: docker ps ‐a ?
Let's clean a bit: docker rm <container_id>
New in 1.13+: docker container prune
•••••
28
![Page 29: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/29.jpg)
Exercise 1.2: run java/javacRemove after exit: docker run ‐‐rm java java ‐version
Let's check our status: docker ps ‐a
Let's compile some code: docker run ‐‐rm java javac
HelloWorld.java
Now that's the real command: docker run ‐‐rm ‐v $PWD:/src
java javac /src/HelloWorld.java
Finally run it: docker run ‐‐rm ‐v $PWD:/src java java ‐
classpath /src HelloWorld
•••
•
•
29
![Page 30: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/30.jpg)
Exercise 1.330
![Page 31: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/31.jpg)
Exercise 1.3: source codeKnockKnockClient.java
KnockKnockServer.java
KnockKnockProtocol.java
•••
31
![Page 32: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/32.jpg)
Exercise 1.3: run java serverCompile KnockKnockServer using Docker
Run KnockKnockServer using Docker
And... surprise...
Compile KnockKnockClient using Docker
Run KnockKnockClient using Docker
•••••
32
![Page 33: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/33.jpg)
Exercise 1.3: hintsKnockKnock server's port can be exposed to the host using ‐p
4444:4444
Then KnockKnock server can be tested with telnet localhost
4444
•
•
33
![Page 34: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/34.jpg)
Exercise 1.3: hintsEach container gets an IP address:
New way: docker inspect ‐f '{{range
.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <c_id>
Older way: docker inspect ‐f '{{
.NetworkSettings.IPAddress }}' <c_id>
Again, telnet <c_ip> 4444
••
•
•
34
![Page 35: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/35.jpg)
Exercise 1.3: hintsContainers can be "linked" within container network
docker create network knock‐knock
Use ‐‐net=knock‐knock to run container in the network
Container name (e.g. ‐‐name=knock‐knock‐server ) will be its
hostname visible to other containers running in the same network
••••
35
![Page 36: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/36.jpg)
Exercise 2.136
![Page 37: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/37.jpg)
Exercise 2.1: build and run PetClinicClone https://github.com/spring‐projects/spring‐petclinic
Create Dockerfile to build runnable PetClinic image
Run PetClinic container out of that image
•••
37
![Page 38: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/38.jpg)
Exercise 2.1: hintsThere is Maven Wrapper inside the repository. Use it to build.
mvnw install spring‐boot:repackage goals will build the
application.
mvnw spring‐boot:run will run the application.
It may be worth putting Maven Home inside a volume.
••
••
38
![Page 39: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/39.jpg)
Exercise 2.239
![Page 40: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/40.jpg)
Exercise 2.2: separate build and runUse Maven Docker image/container to build PetClinic artifacts.
Use the output of that execution and Java image to package runnable
production image as SpringBoot fatjar.
••
40
![Page 41: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/41.jpg)
Exercise 2.2: hintsUse mvn spring‐boot:repackage to build fat JAR artifact.•
41
![Page 42: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/42.jpg)
Exercise 2.342
![Page 43: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/43.jpg)
Exercise 2.3: run PetClinic with adatabaseChange PetClinic application code to use MySQL. For that modify the
data‐access.properties file and verify that the mysql‐
connector‐java artifact is enabled in pom.xml .
Start MySQL container:
docker run ‐e MYSQL_ROOT_PASSWORD=petclinic
‐e MYSQL_DATABASE=petclinic
‐p 3306:3306 mysql:5.7.8
•
•01.
02.
03.
43
![Page 44: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/44.jpg)
Exercise 2.3: hintsUse docker‐compose to start database and PetClinic in one
command.•
44
![Page 45: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/45.jpg)
Docker Compose exampleversion: '2'
services:
db:
ports:
‐ "3306:3306"
image: "mysql:5.7.8"
...
petclinic:
image: "petclinic:1.0"
....
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.45
![Page 46: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/46.jpg)
Conclusion46
![Page 47: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/47.jpg)
Solutionshttps://github.com/aestasit/talks2017gr8confeudockerizedjava
setup.git
47
![Page 48: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/48.jpg)
Home work48
![Page 49: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/49.jpg)
HW1: WebLogicOracle does not share much on GitHub...
But they have this: https://github.com/oracle/dockerimages
Contains Dockerfiles and instruction on how to run WebLogic inside
Docker.
That should be easy to run PetClinic in WebLogic in Docker :)!
•••
•
49
![Page 50: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/50.jpg)
HW2: Jenkins 2Jenkins 2 supports pipelineascode approach with the help of Groovy
DSL.
That DSL supports Dockerbased stages and steps.
How about running Jenkins inside Docker container and make it use
Docker client to start builds in the same host as Jenkins?
Ha, that's going to be DockerinaDocker :)!
•
••
•
50
![Page 51: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/51.jpg)
HW3: PetClinic refactoredPetClinic's architecture is rather monolithic...
Of course, it's time to refactor for more microservices!
Here it goes: https://github.com/springpetclinic/springpetclinic
microservices.
Well, it is already dockerized for you :)!
But you can play with it, to experience what if feels like to have many
containers.
•••
••
51
![Page 52: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/52.jpg)
Readingmaterial
52
![Page 53: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/53.jpg)
Docker documentation
53
![Page 54: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/54.jpg)
Docker labs
54
![Page 55: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/55.jpg)
Book: Containerizing CD in Java
55
![Page 56: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/56.jpg)
Book: Docker for Java Developers
56
![Page 57: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/57.jpg)
Book: Docker Up and Running
57
![Page 58: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/58.jpg)
Book: Using Docker
58
![Page 59: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/59.jpg)
Book: Infrastructure as Code
59
![Page 60: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/60.jpg)
That's all!60
![Page 61: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/61.jpg)
Thank you!61
![Page 62: Dockerized Java Workshop for GR8conf 2017](https://reader031.vdocument.in/reader031/viewer/2022030318/5a647a8f7f8b9a52568b474b/html5/thumbnails/62.jpg)
62