This guide provides a full Ansible playbook to deploy Eclipse Jetty using Docker Compose.
It covers Debian 10 to latest stable, Ubuntu LTS releases, and RHEL 9+ compatible systems.
- name: Install Eclipse Jetty with Docker
hosts: jetty
become: true
vars:
jetty_project_dir: /opt/jetty
jetty_version: "12.1.7"
jetty_image: "jetty:{{ jetty_version }}"
jetty_container_name: jetty
jetty_host_http_port: 8080
jetty_container_http_port: 8080
jetty_host_https_port: 8443
jetty_container_https_port: 8443
jetty_webapps_dir: "{{ jetty_project_dir }}/webapps"
jetty_startd_dir: "{{ jetty_project_dir }}/start.d"
jetty_logs_dir: "{{ jetty_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 Jetty project directory
file:
path: "{{ jetty_project_dir }}"
state: directory
mode: "0755"
- name: Create Jetty webapps directory
file:
path: "{{ jetty_webapps_dir }}"
state: directory
mode: "0755"
- name: Create Jetty start.d directory
file:
path: "{{ jetty_startd_dir }}"
state: directory
mode: "0755"
- name: Create Jetty logs directory
file:
path: "{{ jetty_logs_dir }}"
state: directory
mode: "0755"
- name: Create Docker Compose file
copy:
dest: "{{ jetty_project_dir }}/compose.yml"
mode: "0644"
content: |
services:
jetty:
image: {{ jetty_image }}
container_name: {{ jetty_container_name }}
ports:
- "{{ jetty_host_http_port }}:{{ jetty_container_http_port }}"
- "{{ jetty_host_https_port }}:{{ jetty_container_https_port }}"
volumes:
- {{ jetty_webapps_dir }}:/var/lib/jetty/webapps
- {{ jetty_startd_dir }}:/var/lib/jetty/start.d
- {{ jetty_logs_dir }}:/var/log/jetty
restart: unless-stopped
environment:
- TZ=UTC
- name: Start Jetty container
community.docker.docker_compose_v2:
project_src: "{{ jetty_project_dir }}"
state: present
- name: Verify container is running
community.docker.docker_container_info:
name: "{{ jetty_container_name }}"
register: jetty_container_info
retries: 5
delay: 3
until: jetty_container_info.exists == true
latest.After deployment, access Jetty at:
http://SERVER_IP:8080
Copy your WAR files to the webapps directory:
sudo cp your-app.war /opt/jetty/webapps/
Add configuration files to the start.d directory:
sudo cp http.ini /opt/jetty/start.d/
docker logs jetty
# or
tail -f /opt/jetty/logs/jetty.log
cd /opt/jetty
docker compose stop
docker compose start
Any questions?
Feel free to contact us. Find all contact information on our contact page.