码迷,mamicode.com
首页 > 编程语言 > 详细

JavaEE&Docker 容器示例

时间:2015-01-21 14:57:32      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:


技术分享

准备:jboss、jdk、一个javaee的war包、Dockerfile

注:jboss和jdk可以不用提前准备好,在命令中wget也可以,因为我恰好有,就直接复制了

 Dockerfile内容:

#admln 20150120
FROM ubuntu:14.04
MAINTAINER admln <admln@example.com>
RUN mkdir /usr/jboss
COPY wildfly-8.2.0.Final /usr/jboss/
COPY JavaEEDocker.war /usr/jboss/standalone/deployments/
RUN mkdir /usr/java/
COPY jdk-7u71-linux-x64.tar.gz /usr/java/
WORKDIR /usr/java/
RUN tar -zxf jdk-7u71-linux-x64.tar.gz
RUN update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0_71/bin
/javac 100
RUN update-alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_71/bin/j
ava 100
RUN update-alternatives --display java
RUN java -version
EXPOSE 8080 9990
CMD ["/usr/jboss/bin/standalone.sh", "-c", "standalone-full.xml", "-b", "0.0.0.0
"]

构建:

sudo docker build -t="javaee_docker_jboss" .

构建过程:

Sending build context to Docker daemon 422.1 MB
Sending build context to Docker daemon
Step 0 : FROM ubuntu:14.04
---> b39b81afc8ca
Step 1 : MAINTAINER admln <admln@example.com>
---> Using cache
---> c6410b257abc
Step 2 : RUN mkdir /usr/jboss
---> Running in faae0476fa09
---> bee1d5851e62
Removing intermediate container faae0476fa09
Step 3 : COPY wildfly-8.2.0.Final /usr/jboss/
---> 8d40f390a11e
Removing intermediate container a7a4174c0e79
Step 4 : COPY JavaEEDocker.war /usr/jboss/standalone/deployments/
---> 1335bd7ad129
Removing intermediate container 589fa30b1311
Step 5 : RUN mkdir /usr/java/
---> Running in ac21536064f7
---> cb4703bc284c
Removing intermediate container ac21536064f7
Step 6 : COPY jdk-7u71-linux-x64.tar.gz /usr/java/
---> 35a31c2bc140
Removing intermediate container f4c26050e511
Step 7 : WORKDIR /usr/java/
---> Running in 1217154d1cca
---> a17af238fed9
Removing intermediate container 1217154d1cca
Step 8 : RUN tar -zxf jdk-7u71-linux-x64.tar.gz
---> Running in dfb046ddb86d
---> ea154f6f3896
Removing intermediate container dfb046ddb86d
Step 9 : RUN update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0_71/bin/javac 100
---> Running in ff061540aae3
update-alternatives: using /usr/java/jdk1.7.0_71/bin/javac to provide /usr/bin/javac (javac) in auto mode
---> c3f4118943cc
Removing intermediate container ff061540aae3
Step 10 : RUN update-alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_71/bin/java 100
---> Running in 764aa09ab43f
update-alternatives: using /usr/java/jdk1.7.0_71/bin/java to provide /usr/bin/java (java) in auto mode
---> fddc132f2010
Removing intermediate container 764aa09ab43f
Step 11 : RUN update-alternatives --display java
---> Running in dd123440d778
java - auto mode
link currently points to /usr/java/jdk1.7.0_71/bin/java
/usr/java/jdk1.7.0_71/bin/java - priority 100
Current ‘best‘ version is ‘/usr/java/jdk1.7.0_71/bin/java‘.
---> 0951d9f62f99
Removing intermediate container dd123440d778
Step 12 : RUN java -version
---> Running in 839afe5e2276
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
---> f51af884a45f
Removing intermediate container 839afe5e2276
Step 13 : EXPOSE 8080 9990
---> Running in ed736e99366e
---> bce05a7bdb61
Removing intermediate container ed736e99366e
Step 14 : CMD /usr/jboss/bin/standalone.sh -c standalone-full.xml -b 0.0.0.0
---> Running in fea176d2760b
---> 947def6b3995
Removing intermediate container fea176d2760b
Successfully built 947def6b3995

技术分享

启动容器

 sudo docker run -p 8180:8080 javaee_docker_jboss

技术分享

测试:
技术分享


tomcat版:

技术分享

Dockerfile:

#admln 20150120
FROM ubuntu:14.04
MAINTAINER admln <admln@example.com>
RUN mkdir /usr/tomcat
COPY apache-tomcat-7.0.57.tar.gz /usr/tomcat/
WORKDIR /usr/tomcat/
RUN tar zxf apache-tomcat-7.0.57.tar.gz
COPY JavaEEDocker.war /usr/tomcat/apache-tomcat-7.0.57/webapps/
RUN mkdir /usr/java/
COPY jdk-7u71-linux-x64.tar.gz /usr/java/
WORKDIR /usr/java/
RUN tar -zxf jdk-7u71-linux-x64.tar.gz
RUN update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0_71/bin
/javac 100
RUN update-alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_71/bin/j
ava 100
RUN update-alternatives --display java
RUN java -version
EXPOSE 8080 9990
CMD /usr/tomcat/apache-tomcat-7.0.57/bin/startup.sh && tail -f /usr/tomcat/apach
e-tomcat-7.0.57/logs/catalina.out

构建启动... ...

测试:

技术分享

tomcat和JBoss有点不一样,JBoss启动后默认一直进行的,而tomcat启动后终端就运行完了

所以 CMD 命令中我加了一个 tail -f /usr/tomcat/apache-tomcat-7.0.57/logs/catalina.out

保证终端一直运行。


 

JavaEE&Docker 容器示例

标签:

原文地址:http://www.cnblogs.com/admln/p/javaee_docker.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!