Dockerfile builds tomcat service

The article is based on the construction shared by a buddy on the Internet, as well as my own supplements. 

      Dockerfile application scenario

      Dockerfile runs the command set in batches through scripts, which to a certain extent liberates the manual input of commands to run the program one by one. After writing the Dockerfile script file, create an image through the docker build (docker build [option] path) command, and then let docker read and analyze it. , execution , then repeated construction and update will become very convenient, and it is convenient for the team to share and maintain script files.

     Dockerfile composition

      Dockerfile is composed of line-by-line commands. For the common commands of Dockfile, please refer to my organizer: http://zhongmin2012.iteye.com/blog/2345422 ;

First create a directory to build our environment.

mkdir root/software

Upload tomcat and jdk to this directory.

[root@wls12c web]$ ls
apache-tomcat-7.0.73.tar.gz jdk-7u79-linux-x64.tar.gz

Edit Dockerfile

vi Dockerfile

#pull down centos image, you can query your own through docker images like
FROM daocloud.io/library/centos    
MAINTAINER [email protected]
#copy jdk and tomcat into image If the file is in a recognizable compressed format, docker will help decompress it
ADD ./apache-tomcat-7.0.73.tar.gz /root
ADD ./jdk-7u79-linux-x64.tar.gz /root
#set environment variable
ENV JAVA_HOME /root/jdk1.7.0_79
ENV PATH $JAVA_HOME/bin:$PATH
#define entry point which will be run first when the container starts up
ENTRYPOINT /root/apache-tomcat-7.0.73/bin/startup.sh && tail -F /root/apache-tomcat-7.0.73/logs/catalina.out

build image

[root@wls12c web]$ docker build -t lee/centos:tomcat-centos --rm=true .   #注意点 .
Sending build context to Docker daemon 470.4 MB
Sending build context to Docker daemon
Step 0 : FROM centos
 ---> d83a55af4e75
Step 1 : MAINTAINER [email protected]
 ---> Running in 955747d64da5
 ---> 1619dc8f6d58
................
70/logs/catalina.out
 ---> Running in fe48acf12d70
 ---> 52076383f11b
Removing intermediate container fe48acf12d70
Successfully built 52076383f11b

-t Select to specify the user name, repository name and tag for generating the image

--rm=true specifies to delete intermediate temporary containers during the image generation process.

 

View the newly generated image

[root@wls12c web]$ docker images lee/centos
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
keven/centos        tomcat-centos       52076383f11b        19 minutes ago      516.6 MB

 

运行镜像

[root@wls12c web]$ docker run -d -p 8090:8080 5207
8260fa22aa32126f613a6b64f121e78545ceae01da58c61396968bfafeda3706

-p指定主机80端口与容器8080端口进行绑定

-d 指定容器运行后与当前tty分离,后台运行

5207是镜像的ID前4位。

 

 通过  http://宿主机IP:8090,即可看见我们熟悉的tomcat首页了。

 

另外还有一种自动映射主机端口的启动方法

[root@wls12c web]$ docker run -d -p 8080 --name myweb 520
de39869a8c560e5e0cf48fc6022c05ed9f9a145bdafb897767fa468dc24ebfff
[root@wls12c web]$ docker port de3
8080/tcp -> 0.0.0.0:32768
[root@wls12c web]$ 

这样就要通过http://宿主机IP:32768访问了。

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326383847&siteId=291194637