1. August Penguin 2016
DOCKER
For Java Developers
Ala Hino
Senior Software Engineer
ahino@redhat.com
www.linkedin.com/in/alahino
2. Who Am I?
Test
Test
●
●
●My name is Ala
●I am a Senior Software Engineer @ Red Hat
●I work on oVirt and on RHV (previously known as RHEV)
3. At the end of this session, you will:
Test
Test
●
●
●Understand what Docker is, in general
●Understand how to run a Java application inside a container
●Underdstand advantages of Docker
●
5. What is Docker?
Test
Test
●From Docker website:
●
●
* https://www.docker.com/what-docker
** https://medium.freecodecamp.com/a-beginner-friendly-introduction-to-containers-vms-and-docker-
79a9e3e119b#.tm4j9hsmf
PACKAGE YOUR APPLICATION INTO A STANDARDIZED UNIT FOR SOFTWARE
DEVELOPMENT*
Docker containers wrap a piece of software in a complete filesystem that contains everything needed
to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This
guarantees that the software will always run the same, regardless of its environment*
LIGHTWEIGHT
Containers running on a single machine
share the same operating system
kernel; they start instantly and use less
RAM. Images are constructed from
layered filesystems and share common
files, making disk usage and image
downloads much more efficient*
OPEN
Docker containers are based on open
standards, enabling containers to run on
all major Linux distributions and on
Microsoft Windows -- and on top of any
infrastructure
SECURE BY DEFAULT
Containers isolate applications from one
another and the underlying
infrastructure, while providing an added
layer of protection for the application*
- an open source project to pack, ship and run any application as a lightweight container
- provides os-level virtualization
- lightweight, easy of use, docker hub
Unlike a VM which provides hardware
virtualization, a container provides
operating-system-level virtualization by
abstracting the “user space”. You’ll see
what I mean as we unpack the term
container**
6. I am a Java developer, what do I need to know?
Image: defines the application dependencies and how it is packaged. This is done
using a Dockerfile
Container: the “box” that wraps the application providing everything the application
needs to run
Docker hub: the public Docker registry. The repository where images are published
7. From a Java app to a Docker image
Test
Test
●
●
● 1. Prepare your Java app
1.2. Prepare Dockerfile
2.3. Build the image
3.4. Run & test
4.5. Publish the image
1)
8. 1. My Java App
package august.penguin.yr16;
public class HelloWorld {
public static void main(String... args) {
System.out.println("Hello, World. I am an app inside a container!!!");
}
}
10. 3. Building the image
$ docker build -t ahino/hello-world .
Sending build context to Docker daemon 68.61 kB
Step 0 : FROM maven:latest
---> e674c9bf6d88
Step 1 : COPY src /usr/aug-penguin/src
---> Using cache
---> 18b079e74156
Step 2 : COPY pom.xml /usr/aug-penguin/pom.xml
---> Using cache
---> b0d852d66049
Step 3 : WORKDIR /usr/aug-penguin
---> Using cache
---> 2bb642181d04
Step 4 : RUN mvn clean install
---> Using cache
---> 055cd9eac639
Step 5 : ENTRYPOINT java -cp /usr/aug-penguin/target/classes/ august.penguin.yr16.HelloWorld
---> Using cache
---> 39929150bd68
Successfully built 39929150bd68
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ahino/hello-world latest 5d486d674197 2 hours ago 786.6 MB
11. 4. Running the image
$ time docker run -t ahino/hello-world
Hello, World. I am an app inside a container!!!
real 0m0.706s
user 0m0.013s
sys 0m0.015s
17. 2016-08-02 23:07:52,235 ERROR [org.ovirt.otopi.dialog.MachineDialogParser] (VdsDeploy) [6003e682] Cannot parse input:
java.lang.RuntimeException: Invalid data recieved during bootstrap
at org.ovirt.otopi.dialog.MachineDialogParser.nextEvent(MachineDialogParser.java:370) [otopi.jar:]
at org.ovirt.otopi.dialog.MachineDialogParser.nextEvent(MachineDialogParser.java:405) [otopi.jar:]
at org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase._threadMain(VdsDeployBase.java:304) [bll.jar:]
at org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase.access$800(VdsDeployBase.java:45) [bll.jar:]
at org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase$12.run(VdsDeployBase.java:386) [bll.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_91]
2016-08-02 23:07:52,237 ERROR [org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase] (VdsDeploy) [6003e682] Error during deploy
dialog: java.lang.RuntimeException: Invalid data recieved during bootstrap
at org.ovirt.otopi.dialog.MachineDialogParser.nextEvent(MachineDialogParser.java:370) [otopi.jar:]
at org.ovirt.otopi.dialog.MachineDialogParser.nextEvent(MachineDialogParser.java:405) [otopi.jar:]
at org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase._threadMain(VdsDeployBase.java:304) [bll.jar:]
at org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase.access$800(VdsDeployBase.java:45) [bll.jar:]
at org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase$12.run(VdsDeployBase.java:386) [bll.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_91]
2016-08-02 23:07:52,243 ERROR [org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase] (org.ovirt.thread.pool-9-thread-3) [6003e682]
Error during host rich-el72-host01.usersys.redhat.com install: java.lang.RuntimeException: Invalid data recieved during bootstrap
at org.ovirt.otopi.dialog.MachineDialogParser.nextEvent(MachineDialogParser.java:370) [otopi.jar:]
at org.ovirt.otopi.dialog.MachineDialogParser.nextEvent(MachineDialogParser.java:405) [otopi.jar:]
at org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase._threadMain(VdsDeployBase.java:304) [bll.jar:]
at org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase.access$800(VdsDeployBase.java:45) [bll.jar:]
at org.ovirt.engine.core.bll.hostdeploy.VdsDeployBase$12.run(VdsDeployBase.java:386) [bll.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_91]
18. Docker to the rescue
$ docker run t ovirtengine:3.6.3
19. My second Docker use case
I want to improve logging performance ...
20. Let's Improve Performance (?)
slf4j 1.7.5
PERFORMANCE IMPROVEMENTS The logger factories in most SLF4J modules
namely in jcl-over-slf4j, log4j-over-slf4j, slf4j-jcl, slf4j-jdk14, slf4j-log4j12, and slf4j-
simple now use a ConcurrentHashMap instead of a regular HashMap to cache
logger instances. This change significantly improves logger retrieval times at the cost
of some memory overhead. This improvement was requested in bug #298 by Taras
Tielkes who also provided the relevant patch*
* http://www.slf4j.org/news.html
21. What went wrong?
In my development environment, I build the project using Maven.
pom.xml
In QA environment, they install RPMs.
ovirt-engine.spec.in
...
<slf4j.version>1.7.5</slf4j.version>
...
...
Requires: slf4j >= 1.7.0
...
22. slf4j 1.7.20
Releases 1.7.19 and 1.7.20 suffer from a memory leak. Please use version 1.7.21 or
later instead.
Fixed initialization problem encountered on the Google App Engine platform with
SLF4J version 1.7.19 but not other versions. The problem was reported in SLF4J-
363 by Osvaldo Pinali Doederlein
24. More Docker usages
Running applications is isolated and simpler
E.g.
●- Java applications that use different Java versions
●- Web apps that run on different Tomcat versions