1、创建目录
[root@t-docker chenzx]# mkdir tomcat9
2、在上述目录下touch c.txt,为了演示copy指令的功能
[root@t-docker tomcat9]# touch c.txt
3、将jdk和tomcat安装的压缩包拷贝进上一步目录
[root@t-docker tomcat9]# ls
atlassian-confluence-6.11.0.tar.gz c.txt jdk1.8.0_65.tar.gz
4、新建Dockerfile文件
[root@t-docker tomcat9]# cat Dockerfile
FROM centos
MAINTAINER chenzx
#把宿主机当前上下文的c.txt拷贝到容器/opt路径下
COPY c.txt /opt/container.txt
#用ADD指令把java和tomcat压缩包添加到容器中,并自动解压
ADD atlassian-confluence-6.11.0.tar.gz /opt
ADD jdk1.8.0_65.tar.gz /opt
#安装vim编辑器
RUN yum -y install vim
#设置工作访问时候的WORKDIR路径,登录落脚点
ENV MYPATH /opt
WORKDIR $MYPATH
#配置java与tomcat环境变量
ENV JAVA_HOME /opt/jdk1.8.0_65
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /opt/atlassian-confluence-6.11.0
ENV CATALINA_BASE /opt/atlassian-confluence-6.11.0
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
#容器运行时监听的端口
EXPOSE 8080
#启动时运行tomcat
#ENTRYPOINT ["/opt/atlassian-confluence-6.11.0/bin/startup.sh"]
#CMD ["/opt/atlassian-confluence-6.11.0/bin/catalina.sh","run"]
CMD /opt/atlassian-confluence-6.11.0/bin/startup.sh && tail -F /opt/atlassian-confluence-6.11.0/logs/catalina.out
5、构建
[root@t-docker tomcat9]# docker build -t tomcat9 .
Sending build context to Docker daemon 719MB
Step 1/15 : FROM centos
---> 5182e96772bf
Step 2/15 : MAINTAINER chenzx
---> Running in d04f35bb304d
Removing intermediate container d04f35bb304d
---> b1535d029856
Step 3/15 : COPY c.txt /opt/container.txt
---> ef3569b7b95d
Step 4/15 : ADD atlassian-confluence-6.11.0.tar.gz /opt
---> 0aed885f1740
Step 5/15 : ADD jdk1.8.0_65.tar.gz /opt
---> 56ef4a5d806c
Step 6/15 : RUN yum -y install vim
---> Running in 96d23e66cbc6
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
Step 7/15 : ENV MYPATH /opt
---> Running in f8b147007a67
Removing intermediate container f8b147007a67
---> 88cd40f1df40
Step 8/15 : WORKDIR $MYPATH
---> Running in 55ba5490990a
Removing intermediate container 55ba5490990a
---> 2bdeb9172d40
Step 9/15 : ENV JAVA_HOME /opt/jdk1.8.0_65
---> Running in e5edb170b825
Removing intermediate container e5edb170b825
---> 2b315b03c617
Step 10/15 : ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
---> Running in a3c6d7e8a539
Removing intermediate container a3c6d7e8a539
---> 5a49c2cefc2a
Step 11/15 : ENV CATALINA_HOME /opt/atlassian-confluence-6.11.0
---> Running in 6c105a803c9c
Removing intermediate container 6c105a803c9c
---> 8a4879a4d399
Step 12/15 : ENV CATALINA_BASE /opt/atlassian-confluence-6.11.0
---> Running in 894570c08307
Removing intermediate container 894570c08307
---> 843b28783e33
Step 13/15 : ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
---> Running in 14ea7d7ae882
Removing intermediate container 14ea7d7ae882
---> 2fbdf4cb96b6
Step 14/15 : EXPOSE 8080
---> Running in 0b55f91baea1
Removing intermediate container 0b55f91baea1
---> 340b421dfc43
Step 15/15 : CMD /opt/atlassian-confluence-6.11.0/bin/startup.sh && tail -F /opt/atlassian-confluence-6.11.0/logs/catalina.out
---> Running in 551c8481362e
Removing intermediate container 551c8481362e
---> 4edb0a9de409
Successfully built 4edb0a9de409
Successfully tagged tomcat9:latest
[root@t-docker tomcat9]#
[root@t-docker tomcat9]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat9 latest 4edb0a9de409 3 minutes ago 1.3GB
6、run
[root@t-docker tomcat9]#docker run -d -p 9080:8090 --name myt9 \
-v /volume/test:/opt/atlassian-confluence-6.11.0/test \
-v /volume/tomcatlogs:/opt/atlassian-confluence-6.11.0/logs \
--privileged=true \
tomcat9
-v就是数据卷的意思,volume
[root@t-docker tomcat9]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a4174d4abeba tomcat9 "/bin/sh -c '/opt/at…" 7 seconds ago Up 6 seconds 8080/tcp, 0.0.0.0:9080->8090/tcp myt9
7、验证
[root@t-docker tomcat9]# docker exec a4174d4abeba ls -l
total 0
drwxr-xr-x 1 1000 1000 42 Sep 2 03:41 atlassian-confluence-6.11.0
-rw-r--r-- 1 root root 0 Sep 2 02:38 container.txt
drwxr-xr-x 9 root root 268 Feb 24 2016 jdk1.8.0_65
drwxr-x--- 2 root root 102 Sep 2 03:41 logs
8、综合前述的容器卷测试web服务的发布
以后发版,就在宿主机上的/volume/test里面发版即可,具体测试略。
[root@t-docker tomcat9]# cd /volume/test
[root@t-docker test]# mkdir WEB-INF
[root@t-docker test]# cd WEB-INF/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28916011/viewspace-2213401/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28916011/viewspace-2213401/