标签:sts dex centos7 apache tail shell 好的 comm root
接着上一篇文章来构建Tomcat业务镜像,上篇已经把tomcat基础镜像已经完成了。这次基于tomcat基础镜像构建实际业务镜像。[root@node6 /data/dockerfile/web/tomcat/tomcat-base]#cd ..
[root@node6 /data/dockerfile/web/tomcat]#mkdir tomcat-app1
[root@node6 /data/dockerfile/web/tomcat]#mkdir tomcat-app2
[root@node6 /data/dockerfile/web/tomcat]#cd tomcat-app1
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]#vim Dockerfile
FROM 172.20.7.50/baseimages/centos-tomcat:8.5.33
LABEL maintainer "mr.luo <mr.luo@dklwj.com>"
RUN mkdir -p /data/tomcat/webapps/myapp && useradd tomcat
ADD index.html /data/tomcat/webapps/myapp
ADD run_tomcat.sh /apps/tomcat/bin/run_tomcat.sh
COPY server.xml /apps/tomcat/conf/server.xml
RUN chown -R tomcat.tomcat /apps /data/tomcat/webapps
EXPOSE 8080
CMD ["/apps/tomcat/bin/run_tomcat.sh"]
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]#vim index.html
<h1>tomcat testapp1</h1>
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]#cp /usr/local/apache-tomcat-8.5.33/conf/server.xml ./
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]#vim server.xml
<Host name="localhost" appBase="/data/tomcat/webapps" unpackWARs="true" autoDeploy="true">
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]#vim run_tomcat.sh
#!/bin/bash
echo "1.1.1.1 abc.test.com" >> /etc/hosts
echo "nameserver 223.5.5.5" > /etc/resolv.conf
su - tomcat -c "/apps/tomcat/bin/catalina.sh start"
su - tomcat -c "tail -f /etc/hosts"
# 给脚本添加执行权限
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]#chmod +x run_tomcat.sh
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]#vim build-command.sh
#!/bin/bash
# Dockerfile build shell
docker build -t 172.20.7.50/baseimages/centos-tomcat-web:app1 .
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]#bash build-command.sh
Sending build context to Docker daemon 13.31kB
Step 1/9 : FROM 172.20.7.50/baseimages/centos-tomcat:8.5.33
---> 872c70dd2181
Step 2/9 : LABEL maintainer "mr.luo <mr.luo@dklwj.com>"
---> Using cache
---> e97895b822f7
Step 3/9 : RUN mkdir -p /data/tomcat/webapps/myapp && useradd tomcat
---> Using cache
---> 72bb5e03ae16
Step 4/9 : ADD index.html /data/tomcat/webapps/myapp
---> 1f7213ebca35
Step 5/9 : ADD run_tomcat.sh /apps/tomcat/bin/run_tomcat.sh
---> 810821a8e3ec
Step 6/9 : COPY server.xml /apps/tomcat/conf/server.xml
---> c0e804cc499d
Step 7/9 : RUN chown -R tomcat.tomcat /apps /data/tomcat/webapps
---> Running in a4a8923b3d14
Removing intermediate container a4a8923b3d14
---> ef1bc1eeba9c
Step 8/9 : EXPOSE 8080
---> Running in f0932e1e1990
Removing intermediate container f0932e1e1990
---> bc4e67b65e5e
Step 9/9 : CMD ["/apps/tomcat/bin/run_tomcat.sh"]
---> Running in cba94e6d84e1
Removing intermediate container cba94e6d84e1
---> 3714c600c51e
Successfully built 3714c600c51e
Successfully tagged 172.20.7.50/baseimages/centos-tomcat-web:app1
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]#docker run --name tom1 -it -d -p 8801:8080 172.20.7.50/baseimages/centotomcat-web:app1
6b77dd85d8a74b7475bd3340e501d3bcd0019ffdad2ea0505ca371f52c3d2ae6
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]#docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6b77dd85d8a7 172.20.7.50/baseimages/centos-tomcat-web:app1 "/apps/tomcat/bin/ru…" 6 seconds ago Up 5 seconds 0.0.0.0:8801->8080/tcp tom1
[root@node6 /data/dockerfile/web/tomcat/tomcat-app1]# cd ..
[root@node6 /data/dockerfile/web/tomcat]#cp -rf tomcat-app1/* tomcat-app2/
[root@node6 /data/dockerfile/web/tomcat/tomcat-app2]#vim index.html
<h1>tomcat testapp2</h1>
[root@node6 /data/dockerfile/web/tomcat/tomcat-app2]#vim build-command.sh
#!/bin/bash
# Dockerfile build shell
docker build -t 172.20.7.50/baseimages/centos-tomcat-web:app2 .
[root@node6 /data/dockerfile/web/tomcat/tomcat-app2]#ll
total 24
-rw-r--r-- 1 root root 77 Nov 23 20:56 build-command.sh
-rw-r--r-- 1 root root 398 Nov 23 20:15 Dockerfile
-rw-r--r-- 1 root root 25 Nov 23 20:15 index.html
-rwxr-xr-x 1 root root 205 Nov 23 20:15 run_tomcat.sh
-rw------- 1 root root 7524 Nov 23 20:15 server.xml
[root@node6 /data/dockerfile/web/tomcat/tomcat-app2]#bash build-command.sh
Sending build context to Docker daemon 13.31kB
Step 1/9 : FROM 172.20.7.50/baseimages/centos-tomcat:8.5.33
---> 872c70dd2181
Step 2/9 : LABEL maintainer "mr.luo <mr.luo@dklwj.com>"
---> Using cache
---> e97895b822f7
Step 3/9 : RUN mkdir -p /data/tomcat/webapps/myapp && useradd tomcat
---> Using cache
---> 72bb5e03ae16
Step 4/9 : ADD index.html /data/tomcat/webapps/myapp
---> 5fb4cdb0e0ca
Step 5/9 : ADD run_tomcat.sh /apps/tomcat/bin/run_tomcat.sh
---> ca7037e43dd6
Step 6/9 : COPY server.xml /apps/tomcat/conf/server.xml
---> 944ac27defb1
Step 7/9 : RUN chown -R tomcat.tomcat /apps /data/tomcat/webapps
---> Running in ec169b000f74
Removing intermediate container ec169b000f74
---> 168b359f2e83
Step 8/9 : EXPOSE 8080
---> Running in 86726c38a44a
Removing intermediate container 86726c38a44a
---> d4f8cf67c70c
Step 9/9 : CMD ["/apps/tomcat/bin/run_tomcat.sh"]
---> Running in b323b8b073ca
Removing intermediate container b323b8b073ca
---> 612035ab8d3e
Successfully built 612035ab8d3e
Successfully tagged 172.20.7.50/baseimages/centos-tomcat-web:app2
[root@node6 /data/dockerfile/web/tomcat/tomcat-app2]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
172.20.7.50/baseimages/centos-tomcat-web app2 612035ab8d3e 10 seconds ago 787MB
172.20.7.50/baseimages/centos-tomcat-web app1 3714c600c51e 37 minutes ago 787MB
172.20.7.50/baseimages/centos-tomcat 8.5.35 872c70dd2181 2 hours ago 773MB
172.20.7.50/baseimages/centos7.5-jdk 8.191 19e9d5aa96b6 2 hours ago 759MB
172.20.7.50/baseimages/centos-base 7.5.1804 1f6c2c9e089e 2 hours ago 363MB
centos 7.5.1804 76d6bc25b8a5 6 weeks ago 200MB
[root@node6 /data/dockerfile/web/tomcat/tomcat-app2]#docker run --name tom2 -d -p 8802:8080 172.20.7.50/baseimages/centos-toat-web:app2
e9f08fce2923fc9dd49edf12472d2ef98994126e920168da80c8694ef4a8f0bc
[root@node6 /data/dockerfile/web/tomcat/tomcat-app2]#docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e9f08fce2923 172.20.7.50/baseimages/centos-tomcat-web:app2 "/apps/tomcat/bin/ru…" 6 seconds ago Up 6 seconds 0.0.0.0:8802->8080/tcp tom2
6b77dd85d8a7 172.20.7.50/baseimages/centos-tomcat-web:app1 "/apps/tomcat/bin/ru…" 14 minutes ago Up 14 minutes 0.0.0.0:8801->8080/tcp tom1
标签:sts dex centos7 apache tail shell 好的 comm root
原文地址:http://blog.51cto.com/dklwj/2321338