Docker-Dockerfile方式创建镜像

Dockerfile

FROM centos
MAINTAINER bingjjfly<bingjjfly@docker.org>

ADD /mydocker/tomcat/jdk-8u161-linux-x64.tar.gz /usr/local/
ADD /mydocker/tomcat/apache-tomcat-8.5.54.tar.gz /usr/local/

RUN	yum install -y vim
RUN	yum install -y net-tools

ENV WORK_DIR /usr/local/
WORKDIR $WORK_DIR

ENV JAVA_HOME /usr/local/jdk1.8.0_161
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.54
ENV CATALINA_BASE /usr/local/apache-tomcat-8.5.54
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin

EXPOSE 8080
CMD $CATALINA_HOME/bin/startup.sh && tail -F $CATALINA_HOME/logs/catalina.out

Build

docker build -f /mydocker/tomcat/Dockerfile -t bingjjfly/tomcat:1.0 .

Run

docker run -d -p 8080:8080 --name bingjjfly_tomcat_1.0 \
	-v /mydocker/tomcat/test:/usr/local/apache-tomcat-8.5.54/webapps/test \
	-v /mydocker/tomcat/test_logs:/usr/local/apache-tomcat-8.5.54/logs \
	bingjjfly/tomcat:1.0

Test项目

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
						   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	   version="2.5">
<display-name>test</display-name>
</web-app>

<%@ page contentType="text/html;charset=UTF-8" %>
<html>
    <body>
	Hello Dockerfile!
           <%
                  out.println("Hello World!");
           %>
    </body>
</html>

覆盖CMD命令,不运行容器

docker run bingjjfly/tomcat:1.0 ls -l

不使用交互,直接执行命令  

docker exec -it  bingjjfly_tomcat_1.0 ls -l /usr/local/apache-tomcat-8.5.54/webapps/test

  

posted @ 2020-04-30 14:08  BINGJJFLY  阅读(251)  评论(0编辑  收藏  举报