Skip to content

Example: Using GlassFish Embedded with the docker Command

Ondro Mihalyi edited this page Oct 11, 2024 · 2 revisions

Start GlassFish Embedded

Run GlassFish Embedded runnable JAR (static shell) with the following command:

docker run -it -p 8080:8080 ghcr.io/eclipse-ee4j/glassfish runembedded

This will run GlassFish static shell JAR from the GlassFish installation, which is equivalent to running a standalone GlassFish Embedded JAR. If no applications are deployed, GlassFish Embedded will start an interactive prompt to input commands. For this to work in Docker, the -it arguments are needed.

To display usage instructions, run:

docker run -it -p 8080:8080 ghcr.io/eclipse-ee4j/glassfish runembedded --help

Run an application

To deploy an application with GlassFish Embedded, copy the application into the Docker image or mount the directory that contains it, and then pass the path to it as an argument. For example, if the application myapp.war is copied to the default /opt/glassfish7 directory:

docker run -p 8080:8080 ghcr.io/eclipse-ee4j/glassfish runembedded myapp.war

You can also just copy applications into the /opt/glassfish7/autodeploy directory or mount a directory with applications to it. All applications in that directory will be automatically deployed. For example, if you have applications on a local directory /deployments:

docker run -p 8080:8080 -v /deployments:/opt/glassfish7/autodeploy ghcr.io/eclipse-ee4j/glassfish runembedded

Configure GlassFish Embedded

You can configure GlassFish Embedded by command line aguments after the command runembedded, or by a configuration file. Several options are supported, for example set a different HTTP port or disable HTTP listener, set path to a custom domain configuration, run asadmin commands at startup, deploy applications.

You can also just create a configuration file called glassfish.properties in the default directory /opt/glassfish7, with all the options, including commands to execute and applications to deploy. Or specify path to a different configuration file with the --properties option.

To display usage instructions, run:

docker run -it -p 8080:8080 ghcr.io/eclipse-ee4j/glassfish runembedded --help

This Docker image also supports adding custom Java VM arguments, with the JVM_OPTS environments variable. FOr example, you can specify -XX:MaxRAMPercentage=75 to set maximum heap size to 75% of RAM:

docker run -it -e JVM_OPTS=="-XX:MaxRAMPercentage=75" -p 8080:8080 ghcr.io/eclipse-ee4j/glassfish runembedded

Debug with GlassFish Embedded

To enable debugging, you can either add a custom debugging instruction for the JVM with the JVM_OPTS variable, or you can set one of the following environment variables to true:

  • DEBUG - enables remote debugger on port 9009, doesn't suspend the server
  • SUSPEND - suspends the server right at the startup and continues when a debugger connects on port 9009

Example:

docker run -e SUSPEND=true -p 8080:8080 ghcr.io/eclipse-ee4j/glassfish:latest runembedded