Simple Dockerfile build jdk + tomcat image

As a docker white, we summarize some experience in learning to others. This section describes how to build a simple through Dockerfile jdk + tomcat image.

Preparatory steps:

First, the jdk and tomcat compressed archive package into the following directory specified. Figure:

Then create an empty file Dockerfile.

Preparation step is completed, the official start of construction of the mirror below.

1, edit content Dockerfile

#基础镜像
FROM centos:latest

#创建者信息
MAINTAINER wangpengfei

#添加tomcat和jdk到镜像中
#我的jdk 和 tomcat压缩包在当前目录下,ADD命令会自动解压
ADD jdk-8u181-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-8.5.38.tar.gz /usr/local/

#设置环境变量
ENV JAVA_HOME /usr/local/jdk1.8.0_181/
ENV PATH $JAVA_HOME/bin:$PATH
ENV CLASSPATH .:$JAVA_HOME/lib

#配置启动文件的权限
RUN chmod +x /usr/local/apache-tomcat-8.5.38/bin/*.sh

#指定于外界交互的端口
EXPOSE 8080

#定义在容器启动之后的运行程序
ENTRYPOINT /usr/local/apache-tomcat-8.5.38/bin/startup.sh && /bin/bash && tail -f /usr/local/apache-tomcat-8.5.38/logs/catalina.out

ps: Docker container while only manage a process, if the process exits the container will then withdrew, but this does not mean that the container can only run one process (other processes can run in the background), but not to make the container must have an exit a process executed in the foreground.

ENTRYPOINT parameters must have && / bin / bash && tail -f /usr/local/apache-tomcat-8.5.38/logs/catalina.out, or else after the last vessel will start immediately quit.

2, the mirror Construction

#wpf-image是镜像名称,后面的.必须加
docker build -t wpf-image .

The results appear this command represents the image created.

View built his own mirror image, the command: docker images

3, boot image

#容器8080映射虚拟机8080,前面是的8080是虚拟机的端口,后面是容器的端口
docker run -d -p 8080:8080 wpf-image

In view of the container running the command: docker ps

Finally, we access the virtual machine's 8080 port you can see the start of a tomcat.

This is just a very simple mirror, welcome to correct me.

 

Published 20 original articles · won praise 22 · views 40000 +

Guess you like

Origin blog.csdn.net/yanzi920403/article/details/104004990