1.查看开启的docker容器
[root@bogon ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
2. 查看停止的docker容器
[root@bogon ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS S
fd6821b6e97c redis "docker-entrypoint.s 3 months ago Exited (0) 5 mis7002
ad6f8fd16e15 redis "docker-entrypoint.s 3 months ago Exited (0) 5 mis7001
b193fbe1e400 redis "docker-entrypoint.s 3 months ago Exited (0) 5 mis7000
3.进入src
[root@bogon ~]# . go
[root@bogon src]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 9月 7 04:32 docker
4.进入docker目录
[root@bogon src]# cd docker/
[root@bogon docker]# ll
总用量 475840
-rw-r--r--. 1 root root 8941662 8月 22 2014 apache-tomcat-7.0.55.tar.gz
-rw-r--r--. 1 root root 308329984 9月 2 17:04 centos6.5.tar
-rw-r--r--. 1 root root 138199690 3月 26 2014 jdk-7u51-linux-x64.tar.gz
-rw-r--r--. 1 root root 21389850 6月 22 00:41 jt-manage.war
-rw-r--r--. 1 root root 10384516 6月 22 13:42 ROOT.war
5.在Dockerfile中配置jdk的信息
[root@bogon docker]# vi Dockerfile
6.显示Dockerfile中目录内容
[root@bogon docker]# cat Dockerfile
FROM centos6.5:0.01
ADD jdk-7u51-linux-x64.tar.gz /usr/local/src
ENV JAVA_HOME=/usr/local/src/jdk1.7.0_51
ENV PATH=$JAVA_HOME/bin:$PATH
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
7.显示docker镜像
[root@bogon docker]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
redis latest 8f41ae49db40 4 months ago 183.6 MB
8.导入centos6.5的镜像tar包
[root@bogon docker]# docker load -i centos6.5.tar
[root@bogon docker]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
redis latest 8f41ae49db40 4 months ago 183.6 MB
<none> <none> d1c0a07fd39e 2 years ago 298 MB
9.修改导入的centos6.5.tar包名字和版本号
[root@bogon docker]# docker tag d1c0a07fd39e centos6.5:0.0.1
[root@bogon docker]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
redis latest 8f41ae49db40 4 months ago 183.6 MB
centos6.5 0.0.1 d1c0a07fd39e 2 years ago 298 MB
10.显示Dockerfile的目录内容
[root@bogon docker]# cat Dockerfile
FROM centos6.5:0.01
11.执行本目录下的Dockerfile,-t设置tag
[root@bogon docker]# docker build -t jdkcentos:0.0.1 .
Sending build context to Docker daemon 487.3 MB
Sending build context to Docker daemon
Step 0 : FROM centos6.5:0.01
---> d1c0a07fd39e
Step 1 : ADD jdk-7u51-linux-x64.tar.gz /usr/local/src
---> 322d84d963fb
Removing intermediate container 8b48a80d832c
Step 2 : ENV JAVA_HOME /usr/local/src/jdk1.7.0_51
---> Running in 5053cff84df9
---> cca3015c0714
Removing intermediate container 5053cff84df9
Step 3 : ENV PATH $JAVA_HOME/bin:$PATH
---> Running in a8dd63ed2798
---> 7ff629a27df8
Removing intermediate container a8dd63ed2798
Step 4 : ENV CLASSPATH .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
---> Running in a65322fea503
---> 8494091a042b
Removing intermediate container a65322fea503
Successfully built 8494091a042b
12.显示docker镜像
[root@bogon docker]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
jdkcentos 0.0.1 8494091a042b 17 seconds ago 585 MB
redis latest 8f41ae49db40 4 months ago 183.6 MB
centos6.5 0.01 d1c0a07fd39e 2 years ago 298 MB
13.在Dockerfile中配置tomcat的信息
[root@bogon docker]# vi Dockerfile
14.创建tomcat的实例
[root@bogon docker]# docker build -t tomcatcentos:0.0.1 .
Sending build context to Docker daemon 487.3 MB
Sending build context to Docker daemon
Step 0 : FROM centos6.5:0.01
---> d1c0a07fd39e
Step 1 : ADD jdk-7u51-linux-x64.tar.gz /usr/local/src
---> Using cache
---> 322d84d963fb
Step 2 : ENV JAVA_HOME /usr/local/src/jdk1.7.0_51
---> Using cache
---> cca3015c0714
Step 3 : ENV PATH $JAVA_HOME/bin:$PATH
---> Using cache
---> 7ff629a27df8
Step 4 : ENV CLASSPATH .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
---> Using cache
---> 8494091a042b
Step 5 : ADD apache-tomcat-7.0.55.tar.gz /usr/local/src
---> 3dc304aa564d
Removing intermediate container d4bb3ac41298
Step 6 : ENV CATALINA_HOME /usr/local/src/apache-tomcat-7.0.55
---> Running in cd4dc4c791e0
---> e18de6ef85aa
Removing intermediate container cd4dc4c791e0
Step 7 : ENV PATH $PATH:$CATALINA_HOME/bin
---> Running in e40f35f48dae
---> 8d453bfdea7f
Removing intermediate container e40f35f48dae
Step 8 : EXPOSE 8080
---> Running in dc671caa3690
---> af54f2f5bd92
Removing intermediate container dc671caa3690
Step 9 : CMD /usr/local/src/apache-tomcat-7.0.55/bin/catalina.sh run
---> Running in 5fb164a7a664
---> 4c9a81bdb347
Removing intermediate container 5fb164a7a664
Successfully built 4c9a81bdb347
15.显示docker镜像
[root@bogon docker]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tomcatcentos 0.0.1 4c9a81bdb347 11 seconds ago 598.6 MB
jdkcentos 0.0.1 8494091a042b 4 minutes ago 585 MB
redis latest 8f41ae49db40 4 months ago 183.6 MB
centos6.5 0.0.1 d1c0a07fd39e 2 years ago 298 MB
16.运行tomcat
[root@bogon docker]# docker run -d --name tomcat8080 -p 8080:8080 tomcatcentos:0.01
b751841e2fadc84c9f91044fef2b44a6ced1ed58c782113c24c1fdbeb5773975
17.显示Dockerfile内的信息
[root@bogon docker]# cat Dockerfile
FROM centos6.5:0.01
ADD jdk-7u51-linux-x64.tar.gz /usr/local/src
ENV JAVA_HOME=/usr/local/src/jdk1.7.0_51
ENV PATH=$JAVA_HOME/bin:$PATH
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ADD apache-tomcat-7.0.55.tar.gz /usr/local/src
ENV CATALINA_HOME /usr/local/src/apache-tomcat-7.0.55
ENV PATH=$PATH:$CATALINA_HOME/bin
EXPOSE 8080
CMD ["/usr/local/src/apache-tomcat-7.0.55/bin/catalina.sh","run"]
18.在Dockerfile中配置war包的信息
[root@bogon docker]# vi Dockerfile
19.显示Dockerfile内的信息
[root@bogon docker]# cat Dockerfile
FROM centos6.5:0.01
ADD jdk-7u51-linux-x64.tar.gz /usr/local/src
ENV JAVA_HOME=/usr/local/src/jdk1.7.0_51
ENV PATH=$JAVA_HOME/bin:$PATH
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ADD apache-tomcat-7.0.55.tar.gz /usr/local/src
ENV CATALINA_HOME /usr/local/src/apache-tomcat-7.0.55
ENV PATH=$PATH:$CATALINA_HOME/bin
COPY ROOT.war $CATALINA_HOME/webapps/ROOT/ROOT.war
WORKDIR $CATALINA_HOME/webapps/ROOT
RUN jar xvf ROOT.war
RUN rm -rf ROOT.war
EXPOSE 8080
CMD ["/usr/local/src/apache-tomcat-7.0.55/bin/catalina.sh","run"]
19.创建war包的实例
这里测试用的是自己的一个小项目
[root@bogon docker]# docker build -t war:0.0.1 .
//注意:上面的命令中war:0.0.1 .最后有一个空格点“ .”,不要漏掉了
Sending build context to Docker daemon 487.3 MB
Sending build context to Docker daemon
Step 0 : FROM centos6.5:0.01
---> d1c0a07fd39e
Step 1 : ADD jdk-7u51-linux-x64.tar.gz /usr/local/src
---> Using cache
---> 322d84d963fb
Step 2 : ENV JAVA_HOME /usr/local/src/jdk1.7.0_51
---> Using cache
---> cca3015c0714
Step 3 : ENV PATH $JAVA_HOME/bin:$PATH
---> Using cache
---> 7ff629a27df8
Step 4 : ENV CLASSPATH .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
---> Using cache
---> 8494091a042b
Step 5 : ADD apache-tomcat-7.0.55.tar.gz /usr/local/src
---> Using cache
---> 3dc304aa564d
Step 6 : ENV CATALINA_HOME /usr/local/src/apache-tomcat-7.0.55
---> Using cache
---> e18de6ef85aa
Step 7 : ENV PATH $PATH:$CATALINA_HOME/bin
---> Using cache
---> 8d453bfdea7f
Step 8 : COPY ROOT.war $CATALINA_HOME/webapps/ROOT/ROOT.war
---> 621dd26355ac
Removing intermediate container 3a1f7d859b7d
Step 9 : WORKDIR $CATALINA_HOME/webapps/ROOT
---> Running in 98a2b097de19
---> 9638ca7dcfc3
Removing intermediate container 98a2b097de19
Step 10 : RUN jar xvf ROOT.war
---> Running in 77db04db4bee
created: META-INF/
inflated: META-INF/MANIFEST.MF
created: WEB-INF/
inflated: WEB-INF/admin.txt
created: WEB-INF/classes/
inflated: WEB-INF/classes/c3p0-config.xml
created: WEB-INF/classes/cn/
created: WEB-INF/classes/cn/tedu/
created: WEB-INF/classes/cn/tedu/anno/
inflated: WEB-INF/classes/cn/tedu/anno/Tran.class
created: WEB-INF/classes/cn/tedu/dao/
inflated: WEB-INF/classes/cn/tedu/dao/Dao.class
....................................................................此处为EasyMall的dao加载...............................
inflated: WEB-INF/classes/cn/tedu/dao/OrderDao.class
created: WEB-INF/classes/cn/tedu/dao/impl/
inflated: WEB-INF/classes/cn/tedu/dao/impl/OrderDaoImpl.class
........此处为EasyMall的dao/impl加载..............................
created: WEB-INF/classes/cn/tedu/domain/
inflated: WEB-INF/classes/cn/tedu/domain/Order.class
created: WEB-INF/classes/cn/tedu/exception/
inflated: WEB-INF/classes/cn/tedu/exception/MsgException.class
created: WEB-INF/classes/cn/tedu/factory/
inflated: WEB-INF/classes/cn/tedu/factory/BasicFactory$1.class
inflated: WEB-INF/classes/cn/tedu/factory/BasicFactory.class
created: WEB-INF/classes/cn/tedu/filter/
inflated: WEB-INF/classes/cn/tedu/filter/AutoLoginFilter.class
........此处为EasyMall的filter加载...............................
created: WEB-INF/classes/cn/tedu/service/
inflated: WEB-INF/classes/cn/tedu/service/OrderService.class
created: WEB-INF/classes/cn/tedu/service/impl/
inflated: WEB-INF/classes/cn/tedu/service/impl/OrderServiceImpl.class
created: WEB-INF/classes/cn/tedu/utils/
inflated: WEB-INF/classes/cn/tedu/utils/BeanHandler.class
........此处为EasyMall的utils加载...............................
inflated: WEB-INF/classes/cn/tedu/utils/WebUtils.class
created: WEB-INF/classes/cn/tedu/web/
inflated: WEB-INF/classes/cn/tedu/web/AjaxCheckUsernameServlet.class
.........................................................此处为EasyMall的web加载...............................
inflated: WEB-INF/classes/cn/tedu/web/LoginServlet.class
created: WEB-INF/classes/cn/tedu/web/back/
inflated: WEB-INF/classes/cn/tedu/web/back/BackAjaxEditPnumServlet.class
inflated: WEB-INF/classes/conf.properties
inflated: WEB-INF/classes/merchantInfo.properties
created: WEB-INF/lib/
inflated: WEB-INF/lib/c3p0-0.9.1.2.jar
inflated: WEB-INF/lib/commons-beanutils-1.8.3.jar
inflated: WEB-INF/lib/commons-fileupload-1.2.1.jar
inflated: WEB-INF/lib/commons-io-1.4.jar
inflated: WEB-INF/lib/commons-logging-1.1.1.jar
inflated: WEB-INF/lib/jstl.jar
inflated: WEB-INF/lib/mysql-connector-java-5.0.8-bin.jar
inflated: WEB-INF/lib/standard.jar
created: WEB-INF/tmp/
created: WEB-INF/upload/
created: WEB-INF/upload/1/
created: WEB-INF/upload/1/0/
created: WEB-INF/upload/1/0/c/
created: WEB-INF/upload/1/0/c/f/
created: WEB-INF/upload/1/0/c/f/1/
created: WEB-INF/upload/1/0/c/f/1/d/
created: WEB-INF/upload/1/0/c/f/1/d/1/
created: WEB-INF/upload/1/0/c/f/1/d/1/6/
inflated: WEB-INF/upload/1/0/c/f/1/d/1/6/4ff2cce6-a722-4408-ba94-0af91e61467d_c987f2c1-4123-4d87-83bd-fe2fb221e272.jpg
.......................................此处是EasyMall的图片加载省略.......................................
inflated: WEB-INF/user.txt
inflated: WEB-INF/web.xml
inflated: _foot.jsp
inflated: _head.jsp
inflated: add_order.jsp
created: back/
inflated: back/_left.jsp
.........................此处为EasyMall的jsp加载...................................................
inflated: back/saleList.jsp
inflated: cart.jsp
inflated: confirm.jsp
created: css/
inflated: css/addOrder.css
..........................此处为EasyMall的.css加载...................................................
created: img/
..........................此处为EasyMall的jsp加载...................................................
---> 4f5c628865aa
Removing intermediate container 77db04db4bee
Step 11 : RUN rm -rf ROOT.war
---> Running in cae58dca282c
---> 4a7a022743ff
Removing intermediate container cae58dca282c
Step 12 : EXPOSE 8080
---> Running in 33f77ae59828
---> a69b56411efb
Removing intermediate container 33f77ae59828
Step 13 : CMD /usr/local/src/apache-tomcat-7.0.55/bin/catalina.sh run
---> Running in b9879f0590d8
---> a47a86f087c1
Removing intermediate container b9879f0590d8
Successfully built a47a86f087c1
19.显示docker镜像
[root@bogon docker]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
war 0.0.1 a47a86f087c1 9 seconds ago 620.2 MB
tomcatcentos 0.0.1 4c9a81bdb347 11 minutes ago 598.6 MB
jdkcentos 0.0.1 8494091a042b 15 minutes ago 585 MB
redis latest 8f41ae49db40 4 months ago 183.6 MB
centos6.5 0.01 d1c0a07fd39e 2 years ago 298 MB
21.运行war包
[root@bogon docker]# docker run -d --name easymall -p 8090:8080 war:0.0.1
d99fe2a8662f8b37d4b482a3df99d1296b2ef8d21de361b2661254e81f3a7fc2
22.在浏览器的地址栏上输入localhost:8090就会出来页面了
来源:CSDN
作者:fhf2424045058
链接:https://blog.csdn.net/fhf2424045058/article/details/78051070