dockerfile的编写示例

dockerfile示例



# 版本信息

FROM daocloud.io/centos

MAINTAINER wx "[email protected]"


# OS环境配置

#部署环境不一定联网,弃用wget

#RUN yum install -y wget


#安装JDK与tomcat

RUN mkdir /var/tmp/jdk

RUN mkdir /var/tmp/tomcat

RUN mkdir /var/tmp/webapp

#ADD命令会自动解压,无需在运行tar

If  is a local tar archive in a recognized compression format (identity, gzip, bzip2 or xz) then it is unpacked as a directory. 

ADD jdk-8u162-linux-x64.tar.gz /var/tmp/jdk/

ADD apache-tomcat-8.5.24.tar.gz /var/tmp/tomcat/

ADD sbDemo.war  /var/tmp/webapp


#配置环境变量

ENV JAVA_HOME /var/tmp/jdk/jdk1.8.0_162

ENV CATALINA_HOME /var/tmp/tomcat/apache-tomcat-8.5.24

ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin


#部署war包

RUN cd  /var/tmp/webapp  && cp /var/tmp/webapp/sbDemo.war /var/tmp/tomcat/apache-tomcat-8.5.24/webapps/


#开启内部服务端口

EXPOSE 8080


#启动tomcat服务器

CMD ["./var/tmp/tomcat/apache-tomcat-8.5.24/bin/catalina.sh","run"] && tail -f /var/tmp/tomcat/apache-tomcat-8.5.24/logs/catalina.out



dockerfile编写完成后,运行

docker build -t mytomcat -f dockerfilePath

创建镜像;

使用

docker run -it -p 12345:8080 --name=tomcat-test mytomcat

运行镜像,生成容器

tips:

然后在命令行键入 Ctrl + p + q,使容器在后台运行

你可能感兴趣的:(dockerfile的编写示例)