Created
March 7, 2025 13:40
-
-
Save ludndev/4e000647adfbb82a115b9489732f42bb to your computer and use it in GitHub Desktop.
J2EE Deploiement using Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM eclipse-temurin:17-jdk-alpine | |
# Install required packages | |
RUN apk add curl unzip | |
# Set environment variables | |
ENV GLASSFISH_HOME=/opt/glassfish7 | |
ENV GLASSFISH_URL=https://download.eclipse.org/ee4j/glassfish/glassfish-7.0.9.zip | |
ENV DOMAIN_NAME=domain1 | |
ENV POSTGRESQL_VERSION=42.6.0 | |
# Download and install GlassFish | |
RUN curl -L ${GLASSFISH_URL} -o /tmp/glassfish.zip && \ | |
mkdir -p ${GLASSFISH_HOME} && \ | |
unzip /tmp/glassfish.zip -d /tmp && \ | |
cp -r /tmp/glassfish7/* ${GLASSFISH_HOME}/ && \ | |
rm -rf /tmp/glassfish7 && \ | |
rm -f /tmp/glassfish.zip && \ | |
chmod -R +x ${GLASSFISH_HOME}/bin && \ | |
chmod -R +r ${GLASSFISH_HOME}/glassfish/lib | |
# Set PATH after GlassFish installation | |
ENV PATH=${GLASSFISH_HOME}/bin:$PATH | |
# Download PostgreSQL JDBC driver | |
RUN curl -L https://jdbc.postgresql.org/download/postgresql-${POSTGRESQL_VERSION}.jar -o ${GLASSFISH_HOME}/glassfish/domains/${DOMAIN_NAME}/lib/postgresql.jar && \ | |
chmod 644 ${GLASSFISH_HOME}/glassfish/domains/${DOMAIN_NAME}/lib/postgresql.jar | |
# Verify GlassFish installation | |
RUN asadmin version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
postgres: | |
image: postgres:15-alpine | |
environment: | |
POSTGRES_DB: hotel_db | |
POSTGRES_USER: hotel_user | |
POSTGRES_PASSWORD: hotel_password | |
# ports: | |
# - 5433:5432 | |
volumes: | |
- postgres_data:/var/lib/postgresql/data | |
- ./src/main/resources/data.sql:/docker-entrypoint-initdb.d/data.sql | |
healthcheck: | |
test: ["CMD-SHELL", "pg_isready -U hotel_user -d hotel_db"] | |
interval: 10s | |
timeout: 5s | |
retries: 5 | |
app: | |
image: hotel-reservation:latest | |
# build: | |
# context: . | |
# dockerfile: Dockerfile | |
ports: | |
- 8080:8080 | |
- 9990:9990 | |
depends_on: | |
postgres: | |
condition: service_healthy | |
environment: | |
- POSTGRES_HOST=postgres | |
- POSTGRES_PORT=5432 | |
- POSTGRES_DB=hotel_db | |
- POSTGRES_USER=hotel_user | |
- POSTGRES_PASSWORD=hotel_password | |
volumes: | |
postgres_data: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM hotel-reservation-base:latest | |
# Set environment variables | |
ENV GLASSFISH_HOME=/opt/glassfish7 | |
ENV DOMAIN_NAME=domain1 | |
# Copy application WAR file | |
COPY target/hotel-reservation.war ${GLASSFISH_HOME}/glassfish/domains/${DOMAIN_NAME}/autodeploy/ | |
# Copy GlassFish configuration files | |
COPY src/main/webapp/WEB-INF/glassfish-resources.xml ${GLASSFISH_HOME}/glassfish/domains/${DOMAIN_NAME}/config/ | |
COPY src/main/webapp/WEB-INF/glassfish-web.xml ${GLASSFISH_HOME}/glassfish/domains/${DOMAIN_NAME}/config/ | |
# Expose ports | |
EXPOSE 8080 4848 | |
# Start GlassFish | |
CMD ["asadmin", "start-domain", "--verbose", "domain1"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment