2016年12月29日星期四

OpenShift_019:使用 Dockerfile 部署 .war 到 JBoss EAP 7

环境:OCP 3.3

本文利用已有的 JBoss EAP 7 image 作为 base image,编写 Dockerfile 把 .war 文件拷贝到 EAP 部署目录下。

1. mkdir example

2. cd example

3. vim Dockerfile
FROM registry.example.com:5000/jboss-eap-7/eap70-openshift:latest
#EXPOSE 8080 8888
COPY example.war $JBOSS_HOME/standalone/deployments/ROOT.war

4. 复制 example.war 到 example 目录下

5. oc login -u admin -p admin

6. oc new-project example

7. cd .. 退到 example 上一级目录

8. oc new-app example --name=example --insecure-registry=true
输出如下:
--> Found Docker image 07ebd7e (5 months old) from registry.example.com:5000 for "registry.example.com:5000/jboss-eap-7/eap70-openshift:latest"

    JBoss EAP 7.0
    -------------
    Platform for building and running JavaEE applications on JBoss EAP 7.0

    Tags: builder, javaee, eap, eap7

    * An image stream will be created as "eap70-openshift:latest" that will track the source image
    * A Docker build using binary input will be created
      * The resulting image will be pushed to image stream "example:latest"
      * Use 'start-build --from-dir=DIR|--from-repo=DIR|--from-file=FILE' to trigger a new build
      * WARNING: a binary build was created, you must specify one of --from-dir|--from-file|--from-repo when starting builds
    * This image will be deployed in deployment config "example"
    * Ports 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "example"
      * Other containers can access this service through the hostname "example"

--> Creating resources with label app=example ...
    imagestream "eap70-openshift" created
    imagestream "example" created
    buildconfig "example" created
    deploymentconfig "example" created
    service "example" created
--> Success
    Use 'oc start-build example' to start a build.
    Run 'oc status' to view your app.

9. oc start-build example --from-dir=example
输出如下:
Uploading directory "example" as binary input for the build ...
build "example-1" started

10. oc get pod
NAME              READY     STATUS    RESTARTS   AGE
example-1-build   1/1       Running   0          1m

11. oc logs example-1-build 
输出如下:
Receiving source from STDIN as archive ...
Step 1 : FROM registry.example.com:5000/jboss-eap-7/eap70-openshift
Trying to pull repository registry.example.com:5000/jboss-eap-7/eap70-openshift ...
Pulling repository registry.example.com:5000/jboss-eap-7/eap70-openshift
Pulling image (latest) from registry.example.com:5000/jboss-eap-7/eap70-openshift
Pulling image (latest) from registry.example.com:5000/jboss-eap-7/eap70-openshift, endpoint: http://registry.example.com:5000/v1/
......
......
Pull complete
Status: Downloaded newer image for registry.example.com:5000/jboss-eap-7/eap70-openshift:latest
registry.example.com:5000/jboss-eap-7/eap70-openshift: this image was pulled from a legacy registry.  Important: This registry version will not be supported in future versions of docker.
 ---> 4cfe6e2044dc
Step 2 : COPY example.war $JBOSS_HOME/standalone/deployments/ROOT.war
 ---> 34fbd02ae32e
Removing intermediate container 635e5c7ec247
Step 3 : ENV "OPENSHIFT_BUILD_NAME" "example-1" "OPENSHIFT_BUILD_NAMESPACE" "example"
 ---> Running in a5dedee83edd
 ---> a8bc2e9b518f
Removing intermediate container a5dedee83edd
Successfully built a8bc2e9b518f

Pushing image 172.30.123.246:5000/example/example:latest ...
Pushed 0/6 layers, 2% complete
Pushed 1/6 layers, 18% complete
Pushed 2/6 layers, 34% complete

12. oc expose service example --hostname=example.apps.example.com

13. 访问 http://example.apps.example.com/index.jsp 


14. 删除 project 中所有对象 oc delete all --all

没有评论: