-
Notifications
You must be signed in to change notification settings - Fork 6
Example: Using Embedded GlassFish with the docker Command
Run Embedded GlassFish with the following command:
docker run -p 8080:8080 ghcr.io/eclipse-ee4j/embedded-glassfish
Or with a command for a specific tag (GlassFish version):
docker run -p 8080:8080 ghcr.io/eclipse-ee4j/embedded-glassfish
Open the following URL in the browser to access the HTTP port:
Note: Embedded GlassFish does not include the Administration Console. Use the full GlassFish Server image if you need administrative capabilities.
Stop Embedded GlassFish with the following command:
docker stop CONTAINER_ID
CONTAINER_ID can be found from the output of the following command:
docker ps
You can run an application located in your filesystem with Embedded GlassFish in a Docker container.
Follow these steps:
- Create an empty directory on your filesystem, e.g.
/deployments - Copy the application package to this directory - so that it's for example on the path
/deployments/application.war - Run the following command to start Embedded GlassFish in Docker with your application, where
/deploymentsis the directory created in step 1 and/deployis the directory inside the container where Embedded GlassFish expects applications:
docker run -p 8080:8080 -v /deployments:/deploy ghcr.io/eclipse-ee4j/embedded-glassfish
Alternatively, you can mount a specific WAR file directly:
docker run -p 8080:8080 -v /deployments/application.war:/deploy/application.war ghcr.io/eclipse-ee4j/embedded-glassfish
Then you can open the application in the browser with:
If there's a single application, if will be available under the root (/) context root. If there are multiple applications, each will be available under a context root derived from the name of the application file (e.g. application.war would be deployed under the /application context root).
You can enable debug mode by specifying JVM debug arguments in the standard JAVA_TOOL_OPTIONS environment variable and expose the debug port. For example:
docker run -p 9009:9009 -p 8080:8080 -e 'JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:9009' ghcr.io/eclipse-ee4j/embedded-glassfish
Then connect your debugger to port 9009 on localhost.
If you need to suspend GlassFish startup until you connect the debugger, change suspend=n to suspend=y:
docker run -p 9009:9009 -p 8080:8080 -e 'JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:9009' embedded-glassfish
The following environment variables are available:
-
PATH_GF_HOME- directory that contains Embedded GlassFish JAR and is used as the default working directory (/opt/glassfish) -
PATH_GF_JAR- path to the Embedded GlassFish JAR file -
GLASSFISH_VERSION- version of GlassFish
You can pass custom JVM arguments by setting them in the standard JAVA_TOOL_OPTIONS variable
docker run -p 8080:8080 -e 'JAVA_TOOL_OPTIONS=-Xmx512m -Dmy.property=value' ghcr.io/eclipse-ee4j/embedded-glassfish
Applications placed in the /deploy directory will be automatically deployed at startup. You can either:
Paths to applications in different locations can be passed on command line, e.g.:
docker run -p 8080:8080 ghcr.io/eclipse-ee4j/embedded-glassfish /mydeployments/myapp.war
NOTE: If you point to a path on the command line, the path must exist inside the container. If it's not there, mount a local directory, e.g. using the -v option.
You can create a custom Docker image based on Embedded GlassFish:
FROM ghcr.io/eclipse-ee4j/embedded-glassfish
# Copy your application
COPY myapp.war /deploy/
# Optionally set custom JVM options
ENV JAVA_TOOL_OPTIONS=-Xmx512mdocker run -p 8080:8080 -e JAVA_TOOL_OPTIONS='-Xmx1g -XX:+UseG1GC' ghcr.io/eclipse-ee4j/embedded-glassfishdocker run -d -p 8080:8080 ghcr.io/eclipse-ee4j/embedded-glassfish
CONTAINER_ID=$(docker ps -q --filter ancestor=ghcr.io/eclipse-ee4j/embedded-glassfish)
docker logs -f $CONTAINER_IDdocker run --user 1000 -p 8080:8080 ghcr.io/eclipse-ee4j/embedded-glassfishThis is a simple test example using Embedded GlassFish and TestContainers:
@Testcontainers
public class EmbeddedGlassFishITest {
@Container
private final GenericContainer server = new GenericContainer<>("ghcr.io/eclipse-ee4j/embedded-glassfish")
.withExposedPorts(8080);
@Test
void testServerStartup() throws Exception {
URL url = new URL("http://localhost:" + server.getMappedPort(8080) + "/");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
connection.setRequestMethod("GET");
assertEquals(200, connection.getResponseCode());
} finally {
connection.disconnect();
}
}
}