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
# 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 && \
    unzip -d /opt && \
    rm && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

ENV PATH /opt/glassfish4/bin:$PATH

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 as follows


set -e
export PATH=/opt/glassfish4/bin:$PATH
asadmin start-domain ;
asadmin start-database ;
if [ ! -f /.glassfish_admin_password_changed ]; then
    / ;
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

[root@junolxc ~]# docker port server1  22

[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 sid InRelease
Get:1 sid/main amd64 Packages [9478 kB]
Fetched 9478 kB in 11s (815 kB/s)                                                              
Reading package lists... Done

root@5e16cf923f08:~# cd /

root@5e16cf923f08:/# ./
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 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_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 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] - (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]
     version: - (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:


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:  Bcast:  Mask:
          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:  Mask:
          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 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 :-


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-database &
    $ASADMIN restart-domain   --domaindir /opt/glassfish4/glassfish/domains  domain1 &
    echo "usage: $0 (start|stop|restart|help)"