Monday, January 05, 2015

How to hack Federico Bonelli's docker's image glassfish-4.1 , get Java 1.8.0_40 and Derby Database up and running at a time

# git clone https://github.com/bonelli/tutum-docker-glassfish.git
# cd tutum-docker-glassfish

***********************************
Update Dockerfile as follows :
***********************************
FROM java:8
MAINTAINER Federico Bonelli

RUN apt-get update && \
 apt-get install -y wget unzip pwgen expect apt-utils net-tools vim  && \
  wget http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip && \
    unzip glassfish-4.1.zip -d /opt && \
    rm glassfish-4.1.zip && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

ENV PATH /opt/glassfish4/bin:$PATH

ADD run.sh /run.sh
ADD change_admin_password.sh /change_admin_password.sh
ADD change_admin_password_func.sh /change_admin_password_func.sh
ADD enable_secure_admin.sh /enable_secure_admin.sh
RUN chmod +x /*.sh

RUN apt-get update
RUN apt-get install -y openssh-server
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



# 4848 (administration), 8080 (HTTP listener), 8181 (HTTPS listener), 9009 (JPDA debug port)
EXPOSE 22 4848 8080 8181 9009

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


******************************
Update run.sh as follows
******************************

#!/bin/bash

set -e
export PATH=/opt/glassfish4/bin:$PATH
asadmin start-domain ;
asadmin start-database ;
if [ ! -f /.glassfish_admin_password_changed ]; then
    /change_admin_password.sh ;
fi
echo "=> Restarting Glassfish server"
asadmin restart-domain
echo "=> Starting and running Glassfish server"

***************************************
Build new tutum/glassfish from JAVA:8
***************************************

# docker build -t tutum/glassfish .

**************
Now proceed
**************

[root@junolxc ~]# docker run -d -P --name server1  tutum/glassfish
5e16cf923f089655553d6fd72075510ff1d5aabd1bff47dc9c7d2b1b964e7d9c

[root@junolxc ~]# docker port server1  22
0.0.0.0:49201

[root@junolxc ~]# ssh root@localhost -p 49201


The authenticity of host '[localhost]:49201 ([::1]:49201)' can't be established.
ECDSA key fingerprint is 00:42:38:c7:de:90:22:2c:c9:aa:5e:4f:f9:ec:99:3c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:49201' (ECDSA) to the list of known hosts.
root@localhost's password:
 

root@5e16cf923f08:~# apt-get update
Hit http://http.debian.net sid InRelease
Get:1 http://http.debian.net sid/main amd64 Packages [9478 kB]
Fetched 9478 kB in 11s (815 kB/s)                                                              
Reading package lists... Done

root@5e16cf923f08:~# cd /

root@5e16cf923f08:/# ./run.sh
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.
Starting database in Network Server mode on host 0.0.0.0 and port 1527.
--------- Derby Network Server Information --------
Version: CSS10100/10.10.2.0 - (1582446)  Build: 1582446  DRDA Product Id: CSS10100
-- listing properties --
derby.drda.traceDirectory=/opt/glassfish4/glassfish/databases
derby.drda.maxThreads=0
derby.drda.sslMode=off
derby.drda.keepAlive=true
derby.drda.minThreads=0
derby.drda.portNumber=1527
derby.drda.logConnections=false
derby.drda.timeSlice=0
derby.drda.startNetworkServer=false
derby.drda.host=0.0.0.0
derby.drda.traceAll=false
------------------ Java Information ------------------
Java Version:    1.8.0_40-internal
Java Vendor:     Oracle Corporation
Java home:       /usr/lib/jvm/java-8-openjdk-amd64/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.13.2.el7.x86_64
Java user name:  root
Java user home:  /root
Java user dir:   /
java.specification.name: Java Platform API Specification
java.specification.version: 1.8
java.runtime.version: 1.8.0_40-internal-b09
--------- Derby Information --------
[/opt/glassfish4/javadb/lib/derby.jar] 10.10.2.0 - (1582446)
[/opt/glassfish4/javadb/lib/derbytools.jar] 10.10.2.0 - (1582446)
[/opt/glassfish4/javadb/lib/derbynet.jar] 10.10.2.0 - (1582446)
[/opt/glassfish4/javadb/lib/derbyclient.jar] 10.10.2.0 - (1582446)
------------------------------------------------------
----------------- Locale Information -----------------
Current Locale :  [English/United States [en_US]]
Found support for locale: [cs]
     version: 10.10.2.0 - (1582446)
Found support for locale: [de_DE]
     version: 10.10.2.0 - (1582446)
. .  .  .  .  .

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

=> Modifying password of admin to random in Glassfish
spawn asadmin --user admin change-admin-password
Enter the admin password>
Enter the new admin password>
Enter the new admin password again>
Command change-admin-password executed successfully.

=> Enabling secure admin login
spawn 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.
=> Done!
========================================================================
You can now connect to this Glassfish server using:

     admin:4rX8pqrczo5A

Please remember to change the above password as soon as possible!
========================================================================
=> Restarting Glassfish server
Successfully restarted the domain
Command restart-domain executed successfully.
=> Starting and running Glassfish server


*************************
See for IP obtained :-
*************************

root@5e16cf923f08:/# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:49 
          inet addr:172.17.0.73  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:49/64 Scope:Link
          UP BROADCAST RUNNING  MTU:1500  Metric:1
          RX packets:6903 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3821 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:9962763 (9.5 MiB)  TX bytes:272936 (266.5 KiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:307 errors:0 dropped:0 overruns:0 frame:0
          TX packets:307 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:64517 (63.0 KiB)  TX bytes:64517 (63.0 KiB)


root@5e16cf923f08:/# java -version
openjdk version "1.8.0_40-internal"
OpenJDK Runtime Environment (build 1.8.0_40-internal-b09)
OpenJDK 64-Bit Server VM (build 25.40-b13, mixed mode)


All set.


    Script run.sh ran just once to bring up domain, Derby Database and create
secure admin. Then we create service GlussFish_domain1 via comannd :
# cd /opt/glassfish4/bin
# ./asadmin create-service

and update  GlassFish_domain1 as follows :-

ASADMIN="/opt/glassfish4/glassfish/lib/nadmin"

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