docker制作jdk+tomcat鏡像
docker部署TOMCAT項目
一、內核升級
[root@test01 ~]# uname -r #內核查看確認 2.6.32-696.16.1.el6.x86_64 [root@test01 ~]# [root@test01 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org [root@test01 ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm #安裝yum源 Retrieving http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm Preparing... ########################################### [100%] 1:elrepo-release ########################################### [100%] [root@test01 ~]# yum --enablerepo=elrepo-kernel install kernel-lt -y
修改grub.conf文件 內核升級完畢後修改內核的啟動順序
vim /etc/grub.conf default=0 |
二、docker 安裝
安裝Yum 源 yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 更新Yum yum update 安裝DOCKER yum install docker-io 查看docker版本 docker version 啟動 重啟 停止 service docker start service docker restart service docker stop |
二、制作Tomcat DOCKER鏡像
在tomcat-docker目錄下執行命令touch Dockerfile創建一個Dockerfile文件
Vim Dockerfile內容如下,之後保存
# 設置繼承的鏡像 FROM centos:6.8 # 創建者信息 MAINTAINER qin # 設置環境變量,所有操作都是非交互式的 ENV DEBIAN_FRONTEND noninteractive # 設置tomcat的環境變量 ENV CATALINA_HOME /tomcat ENV JAVA_HOME /java # 復制tomcat和jdk文件到鏡像中 ADD tomcat /tomcat ADD java /java # 復制啟動腳本至鏡像,並賦予腳本可執行權限 ADD run.sh /run.sh RUN chmod +x /*.sh RUN chmod +x /tomcat/bin/*.sh # 暴露接口8091,這是我的tomcat接口,默認為8080 EXPOSE 8091 # 設置自啟動命令 CMD ["/run.sh"]
|
生成鏡像
docker build -t repos_local/centos6.8-jdk151-tomcat8:0.0.1 . Sending build context to Docker daemon 416.5 MB Sending build context to Docker daemon Step 0 : FROM centos:6.8 6.8: Pulling from centos 3690474eb5b4: Pull complete 131c774986bb: Pull complete 418a4141e182: Pull complete e8cf8129749b: Pull complete Digest: sha256:d5c1a93ff48ffe6894f92cf3a967d9552929c51aae279d9f0589508644556bd3 Status: Downloaded newer image for centos:6.8 ---> e8cf8129749b Step 1 : MAINTAINER qincx ---> Running in 816dc6cdfc1a ---> abb8174c6c8c Removing intermediate container 816dc6cdfc1a Step 2 : ENV CATALINA_HOME /tomcat ---> Running in e11aa7f3aa09 ---> a03f42945da8 Removing intermediate container e11aa7f3aa09 Step 3 : ENV JAVA_HOME /java ---> Running in 1c3e278eccb8 ---> 763f32c6f0fd Removing intermediate container 1c3e278eccb8 Step 4 : ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin ---> Running in 3b69460ab841 ---> 9779839b1e58 Removing intermediate container 3b69460ab841 Step 5 : ADD tomcat /tomcat ---> d20bfb40a369 Removing intermediate container f04fe0368412 Step 6 : ADD java /java ---> e941e05d64a2 Removing intermediate container 1c05ea7d45f4 Step 7 : EXPOSE 8080 ---> Running in 2d4f9f6e7d2f ---> b68a2ecaca4b Removing intermediate container 2d4f9f6e7d2f Step 8 : EXPOSE 8762 ---> Running in 729817b4fc18 ---> e7a7fd6d5397 Removing intermediate container 729817b4fc18 Step 9 : EXPOSE 8761 ---> Running in 45c59fa5dd0c ---> e439483994ce Removing intermediate container 45c59fa5dd0c Step 10 : CMD /tomcat/bin/catalina.sh run ---> Running in 7d65e12d018d ---> d3ad75494703 Removing intermediate container 7d65e12d018d Successfully built d3ad75494703 |
查看鏡像
docker images |
刪除DOCKER鏡像
docker rmi 3690474eb5b4 |
停止運行的DOCKER進程
docker rm $(docker ps -a -q) |
docker制作jdk+tomcat鏡像