1. 程式人生 > >docker之GLASSFISH部署

docker之GLASSFISH部署

下載 admin -s add mkdir mnt hello soft rbo

以下安裝以glassfish4做為部署版本
一、前期準備
1.下載或是獲取glassfish4軟件
2.解壓glassfish
3.啟動glassfish ./asadmin start-domain domain1
4.修改管理員密碼 ./asadmin change-admin-password ###此處是需要交互模式的,原密碼為空

二、創建Dockerfile,內容如下:
FROM centos:7
ADD soft/ /mnt
RUN cp -r /mnt/jdk1.8.0_45 /opt/jdk
RUN cp -r /mnt/glassfish4 /opt/glassfish
RUN cp /mnt/build.sh /opt/build.sh

RUN cp /mnt/start.sh /opt/start.sh
RUN sh /opt/build.sh

三、創建build.sh腳本:
export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$PATH
mkdir /opt/webapp #####程序發布基礎目錄
/opt/glassfish/glassfish/bin/asadmin start-domain domain1
echo "AS_ADMIN_PASSWORD=adminadmin">/opt/passwd
/opt/glassfish/glassfish/bin/asadmin --port=4848 --user admin --passwordfile /opt/passwd enable-secure-admin

四、創建start.sh腳本:
export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$PATH
/opt/glassfish/glassfish/bin/asadmin start-domain domain1
echo "AS_ADMIN_PASSWORD=adminadmin">/opt/passwd
/opt/glassfish/glassfish/bin/asadmin deploydir -u admin -W /opt/passwd /opt/webapp/hello ####此處發布一個測試hello程序
/opt/glassfish/glassfish/bin/asadmin stop-domain domain1

/opt/glassfish/glassfish/bin/asadmin start-domain --verbose=true domain1

五、啟動容器:
docker run -d -p 28080:8080 -p 24848:4848 -v /mnt/glassfish/soft/hello:/opt/webapp/hello -v /log/hello/:/opt/glassfish/glassfish/domains/domain1/logs liming/glassfish:4 sh /opt/webapp/hello/start.sh
註: 兩個v 參數分別掛載了程序目錄與日誌目錄
start.sh腳本中的部署目錄要和啟動容器時的掛載目錄相同

六、目錄結構:
./soft
./soft/jdk1.8.0_45
./soft/hello
./soft/hello/index.jsp
./soft/hello/META-INF
./soft/hello/WEB-INF
./soft/hello/start.sh
./soft/build.sh
./soft/glassfish4
./Dockerfile

docker之GLASSFISH部署