Wednesday, November 2, 2016

Run Docker JBoss Wildfly image on AWS ECS

Install Docker on AWS ECS
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html


       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2016.09-release-notes/
[ec2-user@ip-172-31-31-199 ~]$ sudo yum update -y
Loaded plugins: priorities, update-motd, upgrade-helper
No packages marked for update
[ec2-user@ip-172-31-31-199 ~]$  sudo yum install -y docker
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:1.11.2-1.6.amzn1 will be installed
--> Processing Dependency: xfsprogs for package: docker-1.11.2-1.6.amzn1.x86_64
--> Running transaction check
---> Package xfsprogs.x86_64 0:3.2.2-2.20.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package         Arch          Version                   Repository        Size
================================================================================
Installing:
 docker          x86_64        1.11.2-1.6.amzn1          amzn-main         17 M
Installing for dependencies:
 xfsprogs        x86_64        3.2.2-2.20.amzn1          amzn-main        1.7 M

Transaction Summary
================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 18 M
Installed size: 59 M
Downloading packages:
(1/2): docker-1.11.2-1.6.amzn1.x86_64.rpm                |  17 MB     00:00     
(2/2): xfsprogs-3.2.2-2.20.amzn1.x86_64.rpm              | 1.7 MB     00:00     
--------------------------------------------------------------------------------
Total                                               21 MB/s |  18 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : xfsprogs-3.2.2-2.20.amzn1.x86_64                             1/2 
  Installing : docker-1.11.2-1.6.amzn1.x86_64                                                        2/2 
  Verifying  : docker-1.11.2-1.6.amzn1.x86_64                                                        1/2 
  Verifying  : xfsprogs-3.2.2-2.20.amzn1.x86_64                                                      2/2 

Installed:
  docker.x86_64 0:1.11.2-1.6.amzn1                                                                       

Dependency Installed:
  xfsprogs.x86_64 0:3.2.2-2.20.amzn1                                                                     

Complete!
[ec2-user@ip-172-31-31-199 ~]$ sudo service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:    .                                  [  OK  ]
[ec2-user@ip-172-31-31-199 ~]$ sudo usermod -a -G docker ec2-user
[ec2-user@ip-172-31-31-199 ~]$ 

Verify Docker status

[ec2-user@ip-172-31-31-199 ~]$ docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 1.11.2
Storage Driver: devicemapper
 Pool Name: docker-202:1-394626-pool
 Pool Blocksize: 65.54 kB
 Base Device Size: 10.74 GB
 Backing Filesystem: xfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 11.8 MB
 Data Space Total: 107.4 GB
 Data Space Available: 7.223 GB
 Metadata Space Used: 581.6 kB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.147 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Deferred Deletion Enabled: false
 Deferred Deleted Device Count: 0
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 WARNING: Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.93-RHEL7 (2015-01-28)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: null host bridge
Kernel Version: 4.4.23-31.54.amzn1.x86_64
Operating System: Amazon Linux AMI 2016.09
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 995.4 MiB
Name: ip-172-31-31-199
ID: IEGJ:BLTG:7DGR:PNN7:SDZS:3M7H:L6LR:CB3M:52IV:SG2R:O3KF:NZPI
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): false
Registry: https://index.docker.io/v1/
[ec2-user@ip-172-31-31-199 ~]$ 


Run JBoss Wildfly Docker image

[ec2-user@ip-172-31-31-199 ~]$ docker run -it -p 8080:8080 jboss/wildfly 
=========================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /opt/jboss/wildfly

  JAVA: /usr/lib/jvm/java/bin/java

  JAVA_OPTS:  -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true

=========================================================================

21:14:22,924 INFO  [org.jboss.modules] (main) JBoss Modules version 1.5.2.Final
21:14:23,279 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
21:14:23,368 INFO  [org.jboss.as] (MSC service thread 1-1) WFLYSRV0049: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) starting


List Docker processes

[ec2-user@ip-172-31-31-199 ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
0a5959e5cd9e        jboss/wildfly       "/opt/jboss/wildfly/b"   9 minutes ago       Up 9 minutes        0.0.0.0:8080->8080/tcp   adoring_allen


Connect to Wildfly with links browser from other shell

Install links and connect to http:localhost:8080



[ec2-user@ip-172-31-31-199 ~]$ yum install links

[ec2-user@ip-172-31-31-199 ~]$ links http://localhost:8080




Tuesday, November 1, 2016

Install Java EE7 application using JBoss Wildfly Docker image


Docker and WildFly Part 1 - Deployment via Docker volumes 

 
Docker and WildFly Part 2 - Deployment over management API


https://github.com/goldmann/wildfly-docker-deployment-example

Download JBoss Wildfly image
https://hub.docker.com/r/jboss/wildfly/


[dave@localhost wildfly]$ docker run -it jboss/wildfly
Unable to find image 'jboss/wildfly:latest' locally
latest: Pulling from jboss/wildfly

8d30e94188e7: Pull complete 
183bb107e46a: Pull complete 
9ea1527ac190: Pull complete 
d632efeddd98: Pull complete 
11af01a2d795: Pull complete 
Digest: sha256:2bed1e7a68245509de5837435b6250491efe61a86533f5ce6bf94927814076fb
Status: Downloaded newer image for jboss/wildfly:latest
=========================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /opt/jboss/wildfly

  JAVA: /usr/lib/jvm/java/bin/java

  JAVA_OPTS:  -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true

=========================================================================


Use port redirect to see Wildfly running in the browser

[dave@localhost wildfly]$ docker run -it -p 8080:8080 jboss/wildfly 

Wildfly home page
Add access to console using own Dockerfile

[dave@localhost wildfly]$ more Dockerfile 
FROM jboss/wildfly:latest

USER jboss
RUN /opt/jboss/wildfly/bin/add-user.sh admin MY_PASSWORD_TO_ACCESS --silent
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]


Build the Docker image

[dave@localhost wildfly]$ docker build --tag=wildfly-mgmt .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM jboss/wildfly:latest
 ---> 4c99bd2cd264
Step 2 : USER jboss
 ---> Running in de10054221e5
 ---> f3b3e54e823b
Removing intermediate container de10054221e5
Step 3 : RUN /opt/jboss/wildfly/bin/add-user.sh admin MY_PASSWORD_TO_ACCESS --silent
 ---> Running in 9af7cd245555
 ---> 5a29ccf7bef0
Removing intermediate container 9af7cd245555
Step 4 : CMD /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0
 ---> Running in 642784343b49
 ---> 3ea63bcef45a
Removing intermediate container 642784343b49
Successfully built 3ea63bcef45a


Start with port 8080 and 9990 redirected

[dave@localhost wildfly]$ docker run -it -p 8080:8080 -p 9990:9990  wildfly-mgmt

Check the console access via browser on 9990


Deploy Java EE7 app using Maven

Source code for the application GitHub https://github.com/dveselka/wildfly/tree/master/dave-java-ee7-wildfly-full

[dave@localhost dave-java-ee7-wildfly-full]$  mvn clean package wildfly:deploy
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] dave-java-ee7-wildfly-full
[INFO] dave-java-ee7-wildfly-full: EJB Module
[INFO] dave-java-ee7-wildfly-full: WAR Module
[INFO] dave-java-ee7-wildfly-full: EAR Module
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building dave-java-ee7-wildfly-full 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ dave-java-ee7-wildfly-full ---
[INFO] 
[INFO] >>> wildfly-maven-plugin:1.0.2.Final:deploy (default-cli) > package @ dave-java-ee7-wildfly-full >>>
[INFO] 
[INFO] <<< wildfly-maven-plugin:1.0.2.Final:deploy (default-cli) < package @ dave-java-ee7-wildfly-full <<<
[INFO] 
[INFO] --- wildfly-maven-plugin:1.0.2.Final:deploy (default-cli) @ dave-java-ee7-wildfly-full ---

Deployment in Docker Widlfy

05:32:38,366 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started in 4639ms - Started 331 of 577 services (393 services are lazy, passive or on-demand)
05:43:49,778 INFO  [org.jboss.as.repository] (management-handler-thread - 1) WFLYDR0001: Content added at location /opt/jboss/wildfly/standalone/data/content/a1/58abbd7beeb79e23f10486bbefb72f55dc5368/content
05:43:49,861 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0027: Starting deployment of "dave-java-ee7-wildfly-full-ear.ear" (runtime-name: "dave-java-ee7-wildfly-full-ear.ear")
05:43:50,006 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0207: Starting subdeployment (runtime-name: "dave-java-ee7-wildfly-full-web.war")
05:43:50,006 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0207: Starting subdeployment (runtime-name: "dave-java-ee7-wildfly-full-ejb.jar")
05:43:50,168 WARN  [org.jboss.as.connector] (MSC service thread 1-1) WFLYJCA0091: -ds.xml file deployments are deprecated. Support may be removed in a future version.
05:43:50,620 INFO  [org.jboss.as.jpa] (MSC service thread 1-5) WFLYJPA0002: Read persistence.xml for primary
05:43:50,900 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) WFLYJCA0001: Bound data source [java:jboss/datasources/dave-java-ee7-wildfly-fullDS]
05:43:50,966 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 69) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'dave-java-ee7-wildfly-full-ear.ear/dave-java-ee7-wildfly-full-ejb.jar#primary'
05:43:50,977 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0003: Processing weld deployment dave-java-ee7-wildfly-full-ear.ear
05:43:51,095 INFO  [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 69) HHH000204: Processing PersistenceUnitInfo [
    name: primary
    ...]
05:43:51,494 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-1) HV000001: Hibernate Validator 5.2.4.Final
05:43:51,653 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 69) HHH000412: Hibernate Core {5.0.10.Final}
05:43:51,655 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 69) HHH000206: hibernate.properties not found
05:43:51,664 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 69) HHH000021: Bytecode provider name : javassist
05:43:51,864 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 69) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
05:43:52,082 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0003: Processing weld deployment dave-java-ee7-wildfly-full-ejb.jar
05:43:52,090 INFO  [org.jboss.weld.deployer] (MSC service thread 1-5) WFLYWELD0003: Processing weld deployment dave-java-ee7-wildfly-full-web.war
05:43:52,120 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-1) WFLYEJB0473: JNDI bindings for session bean named 'MemberRegistration' in deployment unit 'subdeployment "dave-java-ee7-wildfly-full-ejb.jar" of deployment "dave-java-ee7-wildfly-full-ear.ear"' are as follows:

    java:global/dave-java-ee7-wildfly-full-ear/dave-java-ee7-wildfly-full-ejb/MemberRegistration!dave.service.MemberRegistration
    java:app/dave-java-ee7-wildfly-full-ejb/MemberRegistration!dave.service.MemberRegistration
    java:module/MemberRegistration!dave.service.MemberRegistration
    java:global/dave-java-ee7-wildfly-full-ear/dave-java-ee7-wildfly-full-ejb/MemberRegistration
    java:app/dave-java-ee7-wildfly-full-ejb/MemberRegistration
    java:module/MemberRegistration


Check the application in the browser