Glassfish Application Server im Docker

Workdir

mkdir centos-gf4
cd centos-gf4
wget --no-cookies --header "Cookie:oraclelicense=accept-securebackup-cookie" http://download.oracle.com/glassfish/4.1.1/release/glassfish-4.1.1.zip
wget --no-cookies --header "Cookie:oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u102-b14/server-jre-8u102-linux-x64.tar.gz
vi Dockerfile

Dockerfile

FROM centos:latest

# JAVA_URL=http://download.oracle.com/otn-pub/java/jdk/8u102-b14/server-jre-8u102-linux-x64.tar.gz \
# GF_URL=http://download.oracle.com/glassfish/4.1.1/release/glassfish-4.1.1.zip \
# Maintainer
MAINTAINER Michael Mende <glassfish-on-docker@failover.de>

ENV \
    JAVA_TGZ=/server-jre-8u102-linux-x64.tar.gz \
    JAVA_HOME=/usr/java/default \
    \
    GF_ZIP=/glassfish-4.1.1.zip \
    GF_HOME=/glassfish4 \
    \
    GF_PASSWORD=glassfish
ENV  PATH=${PATH}:${JAVA_HOME}/bin
ENV  PATH=${PATH}:${GF_HOME}/bin

# Install Java
# Install Glassfish
RUN mkdir -pv /usr/java/
ADD .$JAVA_TGZ /usr/java/
ADD .$GF_ZIP $GF_ZIP
RUN \
    useradd -d $GF_HOME -M -s /bin/false glassfish && \
    ls -l /usr/java/ && \
    yum install unzip -y && \
    \
    ln -sv $(ls -d /usr/java/*) $JAVA_HOME && \
    \
    unzip $GF_ZIP && \
    chown -R glassfish:glassfish $GF_HOME && \
    rm $GF_ZIP && \
    \
    yum remove unzip -y && \
    yum update --obsolete -y

# Switch to Glassfish Runtime User
USER glassfish

# Change Glassfish admin password
RUN \
    echo "AS_ADMIN_PASSWORD=" > $GF_HOME/asadmin_passwd && \
    echo "AS_ADMIN_NEWPASSWORD=${GF_PASSWORD}" >> $GF_HOME/asadmin_passwd && \
    asadmin --user=admin --passwordfile=$GF_HOME/asadmin_passwd change-admin-password --domain_name domain1 && \
    asadmin start-domain && \
    echo "AS_ADMIN_PASSWORD=${GF_PASSWORD}" > $GF_HOME/asadmin_passwd && \
    asadmin --user=admin --passwordfile=$GF_HOME/asadmin_passwd enable-secure-admin && \
    asadmin --user=admin stop-domain

# Glassfish-Ports
EXPOSE 4848 8080 8181

# Start asadmin console and the domain
ENTRYPOINT ["asadmin", "start-domain", "-v"]

Build

docker build  -t centos/gf4:latest .

Run

docker run -d --name=centos-gf4 -p 14848:4848 -p 18080:8080 -p 18181:8181 centos/gf4

Commit

docker commit centos-gf4

Restart

docker stop centos-gf4
docker start centos-gf4