Building glassfish container

Below I outline the steps I took to build a glassfish container (I basically followed the steps outlined at https://www.digitalocean.com/community/tutorials/how-to-install-glassfish-4-0-on-ubuntu-12-04-3 but had to add a few extra steps in)

Note

Before you run the ubuntu image and the steps below, you should specify the ports that must be visible in the host environment using docker run -p, otherwise once the image is up and running you will have to rerun the image and this will contain the installed software and settings from the steps below. One option is to follow the steps below, then take a snapshot of the image and store it on the docker hub


  1. sudo apt-get update
  2. udo apt-get install python-software-properties

    In order to use add-apt-repository, you need to install python-software-properties

  3. udo add-apt-repository ppa:webupd8team/java
    This failed, I had to add the following "apt-get software-properties-common" so that the above command is available
  4. sudo apt-get update
    This will ensure the new repo is available to apt-get
  5. sudo apt-get install oracle-java8-installer
    This will install the java jdk
  6. java -version
    Do this to confirm the java version
  7. wget download.java.net/glassfish/4.1.2/release/glassfish-4.1.2.zip

    This will download glassfish, after which we will need to extract it

  8. unzip glassfish-4.1.2.zip

    If unzip is not available, use "apt-get install unzip" to install it on the machine

  9. unzip glassfish-4.1.2.zip -d /opt

    Will extract glassfish to /opt

  10. asadmin start-domain

    This should start glassfish and you should see something like

    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.
  11. asadmin enable-secure-admin
    You should see something like
    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.
  12. asadmin restart-domain
    This will restart the domain so the security constraints take affect 
    Successfully restarted the domain
    Command restart-domain executed successfully.
You should be able to visit the server via your browser on port 4848

info

By default glassfish admin password is empty.

By default admin is NOT secure and therefore cannot be accessed remotely via a browser, follow the steps below

  1. change-admin-password
  2. once completed
  3. enable-secure-admin
  4. restart-domain

Once glassfish is installed, some things to do (if you want another domain)

  1. domain1 user/password combination fails so simply create a new domain on the same admin port as domain1, before executing the command below stop domain1
    1. create-domain --adminport 4848 domain2
  2. Then start domain2
    1. start-domain domain2
  3. Now enable secure admin for remote access but before you do this each domain must have a password
    1. change-admin-password –user admin –domain_name domain2
  4. Now enable remote access to the admin port
    1. enable-secure-admin - -host localhost - -port 4848
  5. Now stop and restart the domain
    1. stop-domain domain2
    2. start-domain domain2
  6. When you access the server from a remote browser you might confronted with information that you are accessing a server without a valid or untrusted certificate

Running the glassfish image

Because I have created a new domain domain2 in the docker container, it has different admin ports and http ports to domain1.  Also, I have created a cluster with 4 server instances, each of these exposing different admin and http ports.  You cannot access these ports unless you use the -p option in the docker run command, so I have created this batch file to run the glassfish docker image once it has been fully commissioned and the cluster has been created.