How to Install GlassFish with Docker (Step-by-Step Guide)
Introduction
Running application servers manually can be time-consuming and difficult to maintain, especially when dealing with dependencies and environment consistency. This is where Docker becomes a game-changer.
By using Docker, you can deploy GlassFish in a lightweight, portable container without worrying about manual installation or configuration issues. This approach is ideal for developers, DevOps engineers, and teams working with microservices or CI/CD pipelines.
In this guide, you will learn how to install and run GlassFish using Docker, including basic configuration and deployment.
What is GlassFish?
GlassFish is an open-source Jakarta EE application server used to build and deploy enterprise Java applications. It supports technologies such as Servlets, JSP, CDI, JPA, and more.
Why Use Docker for GlassFish?
Using Docker provides several advantages:
- Fast and consistent deployment
- No dependency conflicts
- Easy scaling and portability
- Simplified environment management
- Ideal for CI/CD pipelines
Prerequisites
Before starting, ensure your system has:
- Ubuntu 24.04 LTS (or any Linux distro)
- Docker installed
- Basic knowledge of terminal commands
- Internet connection
If Docker is not installed, refer to your Docker installation guide on bckinfo.com.
Step 1: Pull the GlassFish Docker Image
Start by pulling the official GlassFish image from Docker Hub.
docker pull eclipse/glassfish:7.0.12
You can replace the version tag with the latest available version.
Step 2: Run GlassFish Container
Run a container with exposed ports for web access and admin console.
docker run -d \
--name glassfish-server \
-p 8080:8080 \
-p 4848:4848 \
eclipse/glassfish:7.0.12
Explanation:
-dβ Run container in background--nameβ Assign container name-p 8080:8080β Web application port-p 4848:4848β Admin console port
Step 3: Verify Container Status
Check if the container is running:
docker ps
If everything is correct, you will see the GlassFish container in the list.
Step 4: Access GlassFish
Open your browser and access:
- Application URL:
http://localhost:8080 - Admin Console:
http://localhost:4848
You should see the GlassFish welcome page and admin dashboard.
Step 5: View Logs
To check container logs:
docker logs -f glassfish-server
This is useful for troubleshooting startup or deployment issues.
Step 6: Deploy a WAR File
You can deploy applications in multiple ways.
Option 1: Copy WAR into Container
docker cp myapp.war glassfish-server:/opt/glassfish7/glassfish/domains/domain1/autodeploy/
GlassFish will automatically deploy the application.
Option 2: Use Admin CLI
docker exec -it glassfish-server /bin/bash
cd /opt/glassfish7/bin
./asadmin deploy /path/to/app.war
Step 7: Stop and Remove Container
Stop the container:
docker stop glassfish-server
Remove the container:
docker rm glassfish-server
Using Docker Compose (Recommended)
For easier management, use Docker Compose.
Create a file named docker-compose.yml:
version: '3.8'
services:
glassfish:
image: eclipse/glassfish:7.0.12
container_name: glassfish-server
ports:
- "8080:8080"
- "4848:4848"
restart: unless-stopped
Start the service:
docker-compose up -d
Stop the service:
docker-compose down
Persistent Data Configuration
To persist data, mount a volume:
docker run -d \
--name glassfish-server \
-p 8080:8080 \
-p 4848:4848 \
-v glassfish-data:/opt/glassfish7/glassfish/domains \
eclipse/glassfish:7.0.12
This ensures your configurations and deployments are not lost.
Best Practices
- Use specific image versions (avoid
latest) - Enable secure admin for production
- Use volumes for persistence
- Monitor logs regularly
- Integrate with reverse proxy (Nginx)
Troubleshooting
Container not starting?
Check logs:
docker logs glassfish-server
Port already in use?
Change mapping:
-p 9090:8080
Application not deploying?
Ensure WAR file is valid and placed in correct directory.
Conclusion
Running GlassFish with Docker simplifies deployment and eliminates many traditional setup challenges. With just a few commands, you can launch a fully functional Jakarta EE application server ready for development or production.
This approach is ideal for modern DevOps workflows, making your applications more portable, scalable, and easier to manage.
FAQ
Can I use GlassFish in Docker for production?
Yes, but ensure proper security, backups, and monitoring are configured.
What ports does GlassFish use in Docker?
Default ports are 8080 (application) and 4848 (admin console).
How do I persist data in Docker?
Use Docker volumes to store GlassFish domain data.
Is Docker better than manual installation?
For most use cases, yesβDocker is faster, consistent, and easier to manage.











