3.dockerfile制作tomcat8.0.50镜像

现在学习下以Dockerfile自定义image,以tomcat8.0.50为例

1. 编写Dockerfile

cd  /apps/dockerbuilder/tomcat8.0.50 && vim dockerfile

# bash image

FROM harbor.nedy.com/atlas/centos7.5-base:7.5.1804

MAINTAINER lv "[email protected]"

# update source

# yum update -y

# Install JDK 8

RUN cd /tmp && curl -O -s download.nedy.com/jdk1.8.0_65.tar.gz && tar xf jdk1.8.0_65.tar.gz -C /usr/local/

ENV JAVA_HOME /usr/local/jdk1.8.0_65

ENV PATH $PATH:/$JAVA_HOME/bin

# Install tomcat8

RUN cd /tmp && curl -O -s download.nedy.com/apache-tomcat-8.0.50.tar.gz && tar xf apache-tomcat-8.0.50.tar.gz && mv apache-tomcat-8.0.50 /usr/local/tomcat

# Add tomcat.sh

ADD tomcat /etc/init.d/tomcat

RUN chmod 755 /etc/init.d/tomcat

# Expose ports

EXPOSE 8080

# Define default command

#ENTRYPOINT cd /usr/local/tomcat/bin && ./startup.sh

CMD /etc/init.d/tomcat start && tail -f /usr/local/tomcat/logs/catalina.out

*注释

? harbor.nedy.com  是我自己的私有镜像服务器地址

? download.nedy.com 是我自己的文件服务器地址

? harbor.nedy.com/atlas/centos7.5-base:7.5.1804    Centos7.5 系统基础镜像

2. tomcat启动文件

cat    /apps/dockerbuilder/tomcat8.0.50 /tomcat

#!/bin/bash

export JAVA_HOME=/usr/local/jdk1.8.0_65

export TOMCAT_HOME=/usr/local/tomcat


case $1 in 

start) 

  sh $TOMCAT_HOME/bin/startup.sh 

;; 

stop) 

  sh $TOMCAT_HOME/bin/shutdown.sh 

;; 

restart) 

  sh $TOMCAT_HOME/bin/shutdown.sh 

  sh $TOMCAT_HOME/bin/startup.sh 

;; 

esac 

exit 0

3. 验证 Dockerfie

执行 Dockerfie

docker build -t harbor.nedy.com/atlas/tomcat8-jdk8 /apps/dockerbuilder/tomcat8.0.50/

这里我直接加上我的私有镜像服务器标签

启动容器并查看tomcat日志

Docker run -it -p 8888:8080 --name tomcat8.0.50 harbor.nedy.com/atlas/tomcat8-jdk8

参数说明:

-d 后台运行

-it 前台交互式运行

-p 8888:8080 将宿主机的8888端口映射到容器的8080端口

—name  tomcat8.0.50 给容器命名为tomcat8.0.50

浏览器访问

http://10.180.160.113:8888

4.上传到镜像服务器上

docker push harbor.nedy.com/atlas/tomcat8-jdk8

3.dockerfile制作tomcat8.0.50镜像_第1张图片

你可能感兴趣的:(3.dockerfile制作tomcat8.0.50镜像)