Dockerfile使用案例

tomcat8-jdk1.8

#centos基础镜像
FROM centos:7.5.1804
 
# 在镜像里运行的命令
RUN mkdir -p /usr/java/jdk1.8.0_11 \
  && mkdir -p /usr/java/apache-tomcat-8.5.60 \
  && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
  && yum install libnsl vim net-tools kde-l10n-Chinese reinstall glibc-common -y \
  && localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 \
  && echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf \
  && source /etc/locale.conf \
  && yum clean all 
# 将Dockerfile同目录下的jdk1.8.0_11文件复制到镜像中
ADD jdk1.8.0_11 /usr/java/jdk1.8.0_11
ADD apache-tomcat-8.5.60 /usr/java/apache-tomcat-8.5.60

RUN chmod +x /usr/java/jdk1.8.0_11/bin/* \
  && chmod +x /usr/java/apache-tomcat-8.5.60/bin/*
#添加环境变量
ENV JAVA_HOME=/usr/java/jdk1.8.0_11 \
    CLASSPATH=$JAVA_HOME/lib/ \
    CATALINA_HOME=/usr/java/apache-tomcat-8.5.60 \
    PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin \
    LANG=zh_CN.UTF-8 \
    LC_ALL=zh_CN.UTF-8

EXPOSE 8080

CMD ["/usr/java/apache-tomcat-8.5.60/bin/catalina.sh","run"]

生成镜像

docker build -t 镜像名:TAG .

运行容器

docker run -e TZ="Asia/Shanghai" -it -d --name test \
-p 8082:8080 --restart=always \
-v /dir/test/tomcat/webapps:/usr/java/apache-tomcat-8.5.60/webapps \
-v /dir/test/tomcat/conf:/usr/java/apache-tomcat-8.5.60/conf \
-v /dir/test/tomcat/logs:/usr/java/apache-tomcat-8.5.60/logs 镜像名:TAG

 

posted @ 2020-04-07 18:18  MegaloBox  阅读(198)  评论(0编辑  收藏  举报