This guide provides a full Ansible playbook to deploy Eclipse GlassFish using Docker Compose.
It covers Debian 10 to latest stable, Ubuntu LTS releases, and RHEL 9+ compatible systems.
- name: Install Eclipse GlassFish with Docker
hosts: glassfish
become: true
vars:
glassfish_project_dir: /opt/glassfish
glassfish_version: "8.0.0"
glassfish_container_name: glassfish
glassfish_host_http_port: 8080
glassfish_container_http_port: 8080
glassfish_host_admin_port: 4848
glassfish_container_admin_port: 4848
glassfish_config_dir: "{{ glassfish_project_dir }}/config"
glassfish_domains_dir: "{{ glassfish_project_dir }}/domains"
glassfish_logs_dir: "{{ glassfish_project_dir }}/logs"
tasks:
- name: Install Docker prerequisites on Debian/Ubuntu
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Docker prerequisites on RHEL family
dnf:
name:
- dnf-utils
state: present
when: ansible_os_family == "RedHat"
- name: Add Docker GPG key on Debian/Ubuntu
apt_key:
url: https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg
state: present
when: ansible_os_family == "Debian"
- name: Add Docker repository on Debian/Ubuntu
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable"
state: present
when: ansible_os_family == "Debian"
- name: Add Docker repository on RHEL family
yum_repository:
name: docker-ce
description: Docker CE Repository
baseurl: "https://download.docker.com/linux/centos/$releasever/$basearch/stable"
gpgcheck: yes
gpgkey: https://download.docker.com/linux/centos/gpg
when: ansible_os_family == "RedHat"
- name: Install Docker packages on Debian/Ubuntu
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Docker packages on RHEL family
dnf:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
state: present
when: ansible_os_family == "RedHat"
- name: Enable and start Docker service
systemd:
name: docker
state: started
enabled: true
- name: Create GlassFish project directory
file:
path: "{{ glassfish_project_dir }}"
state: directory
mode: "0755"
- name: Create GlassFish config directory
file:
path: "{{ glassfish_config_dir }}"
state: directory
mode: "0755"
- name: Create GlassFish domains directory
file:
path: "{{ glassfish_domains_dir }}"
state: directory
mode: "0755"
- name: Create GlassFish logs directory
file:
path: "{{ glassfish_logs_dir }}"
state: directory
mode: "0755"
- name: Create Dockerfile for GlassFish
copy:
dest: "{{ glassfish_project_dir }}/Dockerfile"
mode: "0644"
content: |
FROM eclipse-temurin:21-jre
ARG GLASSFISH_VERSION={{ glassfish_version }}
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl unzip \
&& rm -rf /var/lib/apt/lists/* \
&& curl -fsSL "https://download.eclipse.org/ee4j/glassfish/glassfish-${GLASSFISH_VERSION}.zip" -o /tmp/glassfish.zip \
&& unzip /tmp/glassfish.zip -d /opt \
&& mv /opt/glassfish8 /opt/glassfish \
&& rm -f /tmp/glassfish.zip
WORKDIR /opt/glassfish/glassfish/bin
EXPOSE 8080 4848
CMD ["./asadmin", "start-domain", "--verbose", "domain1"]
- name: Create Docker Compose file
copy:
dest: "{{ glassfish_project_dir }}/compose.yml"
mode: "0644"
content: |
services:
glassfish:
build:
context: .
container_name: {{ glassfish_container_name }}
ports:
- "{{ glassfish_host_http_port }}:{{ glassfish_container_http_port }}"
- "{{ glassfish_host_admin_port }}:{{ glassfish_container_admin_port }}"
volumes:
- {{ glassfish_config_dir }}:/opt/glassfish/glassfish/domains/domain1/config
- {{ glassfish_domains_dir }}:/opt/glassfish/glassfish/domains
- {{ glassfish_logs_dir }}:/opt/glassfish/glassfish/domains/domain1/logs
restart: unless-stopped
environment:
- TZ=UTC
- name: Build and start GlassFish container
community.docker.docker_compose_v2:
project_src: "{{ glassfish_project_dir }}"
state: present
build: true
- name: Verify container is running
community.docker.docker_container_info:
name: "{{ glassfish_container_name }}"
register: glassfish_container_info
retries: 5
delay: 3
until: glassfish_container_info.exists == true
glassfish_version to the latest stable release before deployment.After deployment, access GlassFish at:
http://SERVER_IP:8080
Admin console:
http://SERVER_IP:4848
Use the admin console or asadmin CLI to deploy applications:
docker exec glassfish /opt/glassfish/glassfish/bin/asadmin deploy /path/to/your-app.war
docker logs glassfish
# or
tail -f /opt/glassfish/logs/server.log
cd /opt/glassfish
docker compose stop
docker compose start
Any questions?
Feel free to contact us. Find all contact information on our contact page.