Sunday, January 04, 2015

Running Glassfish 4.1 in Nova-Docker Container on RDO Juno

 This post follows up
 Docker image been built bellow has pre-installed  JDK 1.8 and GlassFish 4.1,
providing ssh connect to Nova-Docker container ( launched via this image ),
basically extending   rastasheep/ubuntu-sshd ([1]). It allows initialize Glassfish with JPA support manually.  Image provided by ([2]) doesn't bring up Derby database (asadmin start-database is not in CMD script && and attempt just to include this command in via my experience fails).
So Glassfish 4.1 provided by ([2]) doesn't allow to test JSF/JPA applications working with Derby Pool.

Clone ([1]) :-

# git clone
# cd ubuntu-sshd/14.04

Update original Dockerfile as follows :-

FROM       ubuntu:14.04
MAINTAINER Aleksandar Diklic ""

RUN apt-get update
RUN apt-get install -y openssh-server wget tar
RUN mkdir /var/run/sshd
RUN echo 'root:root' |chpasswd
RUN sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config

RUN wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"
RUN cp  jdk-8u25-linux-x64.tar.gz /opt
RUN cd /opt; tar -zxvf jdk-8u25-linux-x64.tar.gz
ENV PATH /opt/jdk1.8.0_25/bin:$PATH
RUN echo "export JAVA_HOME=/opt/jdk1.8.0_25" >> /etc/bash.bashrc
RUN echo "export PATH=$JAVA_HOME/bin:$PATH"  >> /etc/bash.bashrc

RUN apt-get update && \
    apt-get install -y wget unzip pwgen expect && \
    wget && \
    unzip -d /opt && \
    rm && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

EXPOSE 22 4848 8080 8181

CMD    ["/usr/sbin/sshd", "-D"]

Rebuild Image
# docker build -t rastasheep/ubuntu-sshd:14.04  .

Upload image to glance
# . keystonerc_admin
# docker save rastasheep/ubuntu-sshd:14.04 | glance image-create --is-public=True   --container-format=docker --disk-format=raw --name rastasheep/ubuntu-sshd:14.04

Launch instance
# .  keystonerc_demo
# nova boot --image "rastasheep/ubuntu-sshd:14.04" --flavor m1.small --key-name  osxkey    --nic net-id=demo_network-id Glassfish41

Login to dashboard && assign floating IP via dashboard:-

   Login to container :-

   # ssh root@
   root@instance-0000003d:~# hostname

   Update /etc/hosts :-
   root@instance-0000003d:~# cat /etc/hosts
    fe00::0    ip6-localnet
    ff00::0    ip6-mcastprefix
    ff02::1    ip6-allnodes
    ff02::2    ip6-allrouters    localhost instance-0000003d  instance-0000003d
   ::1    localhost ip6-localhost ip6-loopback

Any next container restart requires same update of /etc/hosts via

  Initialize server :-
  root@instance-0000003d:/# cd /opt
  root@instance-0000003d:/opt# chown -R root:root jdk1.8.0_25
  root@instance-0000003d:/opt# cd glassfish4/bin
   asadmin> start-database
Starting database in Network Server mode on host and port 1527.
--------- Derby Network Server Information --------
Version: CSS10100/ - (1582446)  Build: 1582446  DRDA Product Id: CSS10100
-- listing properties --
------------------ Java Information ------------------
Java Version:    1.8.0_25
Java Vendor:     Oracle Corporation
Java home:       /opt/jdk1.8.0_25/jre
Java classpath:  /opt/glassfish4/glassfish/lib/asadmin/cli-optional.jar:/opt/glassfish4/javadb/lib/derby.jar:/opt/glassfish4/javadb/lib/derbytools.jar:/opt/glassfish4/javadb/lib/derbynet.jar:/opt/glassfish4/javadb/lib/derbyclient.jar
OS name:         Linux
OS architecture: amd64
OS version:      3.10.0-123.el7.x86_64
Java user name:  root
Java user home:  /root
Java user dir:   /opt/glassfish4/bin Java Platform API Specification
java.specification.version: 1.8
java.runtime.version: 1.8.0_25-b17
--------- Derby Information --------
[/opt/glassfish4/javadb/lib/derby.jar] - (1582446)
[/opt/glassfish4/javadb/lib/derbytools.jar] - (1582446)
[/opt/glassfish4/javadb/lib/derbynet.jar] - (1582446)
[/opt/glassfish4/javadb/lib/derbyclient.jar] - (1582446)
----------------- Locale Information -----------------
Current Locale :  [English/United States [en_US]]
Found support for locale: [cs]
     version: - (1582446)
Found support for locale: [de_DE]
.  .  .  .  .

Starting database in the background.
Log redirected to /opt/glassfish4/glassfish/databases/derby.log.
Command start-database executed successfully.

asadmin> start-domain
Waiting for domain1 to start ......
Successfully started the domain : domain1
domain  Location: /opt/glassfish4/glassfish/domains/domain1
Log File: /opt/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.

asadmin> change-admin-password
Enter admin user name [default: admin]>
Enter the admin password>
Enter the new admin password>
Enter the new admin password again>
Command change-admin-password executed successfully.

asadmin> enable-secure-admin
Enter admin user name>  admin
Enter admin password for user "admin">
You must restart all running servers for the change in secure admin to take effect.
Command enable-secure-admin executed successfully.

asadmin> restart-domain
Successfully restarted the domain
Command restart-domain executed successfully.
asadmin> exit
Command multimode executed successfully.

root@instance-0000003d:/opt/glassfish4/bin# ./asadmin create-service
Found the Linux Service and successfully uninstalled it.
The Service was created successfully. Here are the details:
Name of the service:domain1
Type of the service:Domain
Configuration location of the service:/etc/init.d/GlassFish_domain1
User account that will run the service: root
You have created the service but you need to start it yourself.  Here are the most typical Linux commands of interest:

* /etc/init.d/GlassFish_domain1 start
* /etc/init.d/GlassFish_domain1 stop
* /etc/init.d/GlassFish_domain1 restart

For your convenience this message has also been saved to this file: /opt/glassfish4/glassfish/domains/domain1/PlatformServices.log
Command create-service executed successfully.

Service GlassFish_domain1


case "$1" in
    $ASADMIN start-domain    --domaindir /opt/glassfish4/glassfish/domains  domain1 &
    $ASADMIN start-database &
    $ASADMIN stop-domain   --domaindir /opt/glassfish4/glassfish/domains  domain1 &
    $ASADMIN stop-databse &
    $ASADMIN restart-domain   --domaindir /opt/glassfish4/glassfish/domains  domain1 &
    echo "usage: $0 (start|stop|restart|help)"