一、dockerfile构建JAVA网站镜像
[root@ansible-server Dockerfile]# tree tomcat/
tomcat/
├── apache-tomcat-8.0.46.tar.gz
├── Dockerfile
├── index.html
├── jdk-8u45-linux-x64.tar.gz
└── server.xml
[root@ansible-server Dockerfile]# tree app/
app/
└── webapps
└── ROOT
└── index.html
#Dockerfile
[root@ansible-server tomcat]# cat Dockerfile
FROM centos:7
MAINTAINER https://www.cnblogs.com/nulige
ADD jdk-8u45-linux-x64.tar.gz /usr/local
ENV JAVA_HOME /usr/local/jdk1.8.0_45
add apache-tomcat-8.0.46.tar.gz /usr/local
COPY server.xml /usr/local/apache-tomcat-8.0.46/conf
RUN rm -f /usr/local/*.tar.gz
WORKDIR /usr/local/apache-tomcat-8.0.46
EXPOSE 8080
ENTRYPOINT ["./bin/catalina.sh", "run"]
#创建tomcat镜像
docker build -t tomcat:8.0.46 .
#查看镜像
[root@ansible-server ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 8.0.46 bead16774a61 About a minute ago 556MB
#创建挂载目录
mkdir -p /app/webapps/
#构建容器
docker run -itd \
--name=tomcat \
-p 8080:8080 \
--mount type=bind,src=/app/webapps/,dst=/usr/local/apache-tomcat-8.0.46/webapps \
tomcat:8.0.46
#查看容器
[root@ansible-server ~]# docker logs fd2098533ad8
Using CATALINA_BASE: /usr/local/apache-tomcat-8.0.46
Using CATALINA_HOME: /usr/local/apache-tomcat-8.0.46
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-8.0.46/temp
Using JRE_HOME: /usr/local/jdk.8.0_45
Using CLASSPATH: /usr/local/apache-tomcat-8.0.46/bin/bootstrap.jar:/usr/local/apache-tomcat-8.0.46/bin/tomcat-juli.jar
./bin/catalina.sh: line 365: /usr/local/jdk.8.0_45/bin/java: No such file or director
#需要发布的网站代码
[root@ansible-server webapps]# mkdir -p /app/webapps/ROOT
[root@ansible-server webapps]# echo "welcome nulige" >>/app/webapps/ROOT/index.html
[root@ansible-server webapps]# ll
total 0
drwxr-xr-x. 2 root root 24 May 28 16:23 ROOT
[root@ansible-server webapps]# cd ROOT/
[root@ansible-server ROOT]# ll
total 4
-rw-r--r--. 1 root root 15 May 28 16:23 index.html
[root@ansible-server ROOT]# cat index.html
welcome nulige
#访问网站
[root@ansible-server ROOT]# curl http://59.47.71.229:8080
welcome nulige
#在浏览器上面访问
http://59.47.71.229:8080/
welcome nulige