26. How to setup Docker on Linux
● curl -sSL https://get.docker.com/ | sh
● Docker client, the Docker daemon, and
any containers run directly on your
localhost
● Can address ports on a Docker
container using standard localhost
addressing such as localhost:PORT or
Container-IP:PORT
27. How to setup Docker on Mac
● Goto https://docs.docker.
com/engine/installation/mac/
● Docker daemon is running inside a
Linux VM called default
● The default is a lightweight Linux VM
(~24MB download, and boots in
approximately 5s)
28. How to setup Docker on Windows
● Goto https://docs.docker.
com/engine/installation/windows/
● Docker daemon is running inside a
Linux VM called default
● The default is a lightweight Linux VM
(~24MB download, and boots in
approximately 5s)
32. Why Need of Docker Cluster?
● Avoid single point of failure
● Make horizontally scalable
● Have more granular management for distributed applications
(microservices)
● Self healing systems
36. What is Kubernetes?
● Manage a cluster of Linux containers as a single system to
accelerate Dev and simplify Ops.
● Initiated by Google
● Massive community support
38. Key Concepts of Kubernetes
● Pod - A group of Containers
● Labels - Labels for identifying pods
● Proxy/Service - A load balancer for Pods
● etcd - A metadata service
● cAdvisor - Container Advisor provides resource
usage/performance statistics
● Replication Controller - Manages replication of pods
● Scheduler - Schedules pods in worker nodes
● API Server - Kubernetes API server
50. Agenda - Session 2
● Running a Microservice JAR in a Docker
container
● Building a Docker image with Maven
● Running a Java server application in a
Docker container
● Talking to the Docker API in Java
● Next generation continuous delivery
with Jenkins & Docker
● Deploying Java server applications in
production
Imesh Gunaratne
Senior Technical Lead, WSO2
53. What is a Microservice?
● “Microservice is an architectural style for developing a single
application as a suite of small services, each running in its
own process and communicating with lightweight mechanisms,
often an HTTP resource API” - Martin Fowler
http://martinfowler.com/articles/microservices.html
56. WSO2 MSF4J Hello World Sample
package org.wso2.msf4j.example;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
/**
* Hello service resource class.
*/
@Path("/hello")
public class HelloService {
@GET
@Path("/{name}")
public String hello(@PathParam("name") String name) {
return "Hello " + name;
}
}
57. WSO2 MSF4J Hello World Sample
git clone https://github.com/wso2/msf4j.git
# Build msf4j, this requires JDK 1.8
cd msf4j/
mvn clean install
# Build hello world sample
cd samples/helloworld/
mvn clean install
# Run self contained JAR
java -jar target/helloworld-*.jar
curl http://localhost:8080/hello/java-colombo
58. How to run a Microservice JAR in a
Docker Container
>docker run
# Mount local folder to container
-v ~/dev/wso2/msf4j/samples/helloworld/target/:/tmp/
# Ports to be exposed
-p 8080:8080
# Docker image tag
-t java
# Command to be run
java -jar /tmp/helloworld-1.0.0-SNAPSHOT.jar
61. Using Spotify Docker Maven Plugin
Add Docker Maven plugin to the pom.xml file:
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.0</version>
<configuration>
<imageName>helloworld</imageName>
<baseImage>java</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<!-- copy the service's jar file from target into the root directory of the image -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
62. Using Spotify Docker Maven Plugin
1. Build Hello World Docker image using Maven:
>mvn clean package docker:build
2. List Docker images:
>docker images
3. Run Hello World Docker container:
>docker run -p 8080:8080 helloworld
67. Docker API Clients for Java
● Docker Java API
○ https://github.com/docker-java/docker-java
● Docker Client
○ https://github.com/spotify/docker-client
● jClouds Docker API Client
○ https://github.com/jclouds/jclouds-labs/tree/master/docker
● Other API Clients:
● https://docs.docker.com/engine/reference/api/remote_api_client_libraries/