DOCKER 通过TOMCAT镜像部署WEB项目

1、拉取镜像

[[email protected] buildtomcat1]# docker search tomcat

DOCKER 通过TOMCAT镜像部署WEB项目

[[email protected] ~]# docker pull tomcat
Using default tag: latest
Trying to pull repository docker.io/library/tomcat ... 
latest: Pulling from docker.io/library/tomcat
cd8eada9c7bb: Pull complete 
c2677faec825: Pull complete 
fcce419a96b1: Pull complete 
00d7fcb5828a: Pull complete 
f8c860563d60: Pull complete 
46f754145d12: Pull complete 
bff15a87739e: Pull complete 
6b5d3f0336b9: Pull complete 
1d858972966c: Pull complete 
4f2dc2e148d0: Pull complete 
db18a2f7d48d: Pull complete 
Digest: sha256:ff678df6c37e7837b80d7b4532ce49f7b152545a7bb8fa987701d13516129141
Status: Downloaded newer image for docker.io/tomcat:latest

 

2、简单写一个Dockerfile

[[email protected] buildtomcat1]# cat Dockerfile 
from tomcat
MAINTAINER bcd[email protected]
#RUN rm -rf /usr/local/tomcat/webapps/*
COPY jboss-helloworld.war /usr/local/tomcat/webapps
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

 

 

把待发布的应用拷到构建镜像的目录下

[[email protected] buildtomcat1]# pwd
/75shell/docker/buildtomcat1
[[email protected] buildtomcat1]# ll
总用量 9
-rwxr-xr-x 1 root root  232 1月  19 18:26 Dockerfile
-rwxr-xr-x 1 root root 7735 1月  19 13:48 jboss-helloworld.war

 

3、构建镜像,启动容器,测试访问

[[email protected] buildtomcat1]# docker build -t local/tomcat .
Sending build context to Docker daemon 10.75 kB
Step 1/5 : FROM tomcat
 ---> 1a51cb5e3006
Step 2/5 : MAINTAINER [email protected]
 ---> Running in 6e3088a6776e
 ---> ffaaa14fb663
Removing intermediate container 6e3088a6776e
Step 3/5 : COPY jboss-helloworld.war /usr/local/tomcat/webapps
 ---> ba44d3f8443c
Removing intermediate container 678923360cca
Step 4/5 : ENV TZ Asia/Shanghai
 ---> Running in 8291d17fbeff
 ---> b62bc4ccb5af
Removing intermediate container 8291d17fbeff
Step 5/5 : RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
 ---> Running in 1a912c9cbe3b

 ---> 5c85c7589930
Removing intermediate container 1a912c9cbe3b
Successfully built 5c85c7589930
[[email protected] buildtomcat1]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
local/tomcat        latest              5c85c7589930        6 seconds ago       462 MB
docker.io/tomcat    latest              1a51cb5e3006        2 weeks ago         462 MB
docker.io/mysql     latest              102816b1ee7d        3 weeks ago         486 MB
docker.io/nginx     <none>              568c4670fa80        7 weeks ago         109 MB

 

[[email protected] buildtomcat1]# docker run -d -p 8081:8080 local/tomcat

 

此时应用已经跑起来了,通过映射的主机端口加项目路径可以访问到应用

 

DOCKER 通过TOMCAT镜像部署WEB项目