- A+
所属分类:未分类
1.获取基础镜像
docker pull centos
2.准备Jdk和Tomcat
2-1 下载jdk和tomcat
我这里用的是:apache-tomcat-7.0.56-windows-i64.zip 和 jdk-8u77-linux-x64.tar.gz
2-2 解压
unzip apache-tomcat-7.0.56-windows-i64.zip tar zxvf jdk-8u77-linux-x64.tar.gz
2-3 将文件复制到自定义文件夹
[root@k4151v /home/xubo-iri/tomcatfile]# pwd /home/xubo-iri/tomcatfile [root@k4151v /home/xubo-iri/tomcatfile]# ls apache-tomcat-7.0.56-windows-i64.zip Dockerfile jdk1.8.0_77 jdk-8u77-linux-x64.tar.gz tomcat
3.准备Dockerfile文件
文件内容如下:
#基础镜像 FROM 10.209.3.81/library/centos #镜像维护者 MAINTAINER xubo #复制jre文件夹到镜像中 #./jdk1.8.0_77 物理机中文件位置,必须为相对当前Dockerfile的相对路径 #/usr/soft/java/jdk8 镜像中的位置,docker会自动创建目录 COPY ./jdk1.8.0_77 /usr/soft/java/jdk8 #配置JAVA环境变量 ENV JAVA_HOME /usr/soft/java/jdk8 ENV CLASSPATH $JAVA_HOME/lib ENV PATH $PATH:$JAVA_HOME/bin #复制tomcat文件夹到镜像中 COPY ./tomcat /usr/soft/tomcat7 #配置tomcat环境变量 ENV CATALINA_HOME /usr/soft/tomcat7 #我实际操作的时候,即使是没有项目的tomcat启动也会很慢,加上这句话,启动会变快,大家可以试试,但是不知道有没有其他影响 RUN echo -e \\nJAVA_OPTS="-Djava.security.egd=file:/dev/./urandom" >> /usr/soft/tomcat7/bin/setclasspath.sh #启动tomcat命令 CMD usr/soft/tomcat7/bin/catalina.sh run
注:1.文件名必须为Dockerfile 2.如果复制此文件,将汉字注释去掉;2.FROM的镜像我用的自己的私有镜像库,如果没有的话,就直接写出FROM centos就行
4.制作镜像
docker build -t centos/tomcat7/jdk8:v1.0 .
执行命令如下:
[root@k4151v /home/xubo-iri/tomcatfile]# docker build -t centos/tomcat7/jdk8:v1.0 . Sending build context to Docker daemon 575.7 MB Step 1/10 : FROM 10.209.3.81/library/centos ---> e934aafc2206 Step 2/10 : MAINTAINER xubo ---> Running in 859693c78726 ---> 366f8064cb03 Removing intermediate container 859693c78726 Step 3/10 : COPY ./jdk1.8.0_77 /usr/soft/java/jdk8 ---> ddfad628e597 Removing intermediate container 6fb16675f6c2 Step 4/10 : ENV JAVA_HOME /usr/soft/java/jdk8 ---> Running in 85c9b1d70b76 ---> fc08af5f455e Removing intermediate container 85c9b1d70b76 Step 5/10 : ENV CLASSPATH $JAVA_HOME/lib ---> Running in e7521282633c ---> 2e297b8de8b6 Removing intermediate container e7521282633c Step 6/10 : ENV PATH $PATH:$JAVA_HOME/bin ---> Running in 33761cbd8c2a ---> a68b4482b249 Removing intermediate container 33761cbd8c2a Step 7/10 : COPY ./tomcat /usr/soft/tomcat7 ---> 7a577e65e9ac Removing intermediate container a443523d4dba Step 8/10 : ENV CATALINA_HOME /usr/soft/tomcat7 ---> Running in 54842d1cf533 ---> 8e09756c12b0 Removing intermediate container 54842d1cf533 Step 9/10 : RUN echo -e \\nJAVA_OPTS="-Djava.security.egd=file:/dev/./urandom" >> /usr/soft/tomcat7/bin/setclasspath.sh ---> Running in a2a2653ea32a ---> 1a32ba340907 Removing intermediate container a2a2653ea32a Step 10/10 : CMD usr/soft/tomcat7/bin/catalina.sh run ---> Running in 43fc63793ac4 ---> 76dd0e84d9d8 Removing intermediate container 43fc63793ac4 Successfully built 76dd0e84d9d8
查看镜像:输入docker images命令,如下:
[root@k4151v /home/xubo-iri/tomcatfile]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos/tomcat7/jdk8 v1.0 76dd0e84d9d8 About a minute ago 580 MB
5.运行测试
docker run -it --privileged -p 8080:8080 centos/tomcat7/jdk8:v1.0
6.测试访问
通过浏览器访问,就会出现tomcat界面,如下:
7.通过现成的centos镜像制作
下载centos镜像
docker pull centos
创建目录,目录下准备到tomcat,java ,我这里创建了个/data/soft目录,然后启动centos
docker run -i -t -v /root/soft/:/mnt/software/ centos /bin/bash
然后进入到/mnt/software目录下执行如下命令:
#mv jdk1.8.0_77/ /opt/jdk/
#mv apache-tomcat-7.0.56 /opt/tomcat/
#touch /root/run.sh
#vi /root/run.sh
其中,run.sh的内容如下:
#!/bin/bash
export JAVA_HOME=/opt/jdk/
export PATH=$JAVA_HOME/bin:$PATH
sh /opt/tomcat/bin/catalina.sh run
然后保存后,给予赋权,退出docker,命令如下:
#chmod u+x /root/run.sh #exit
查看本地容器,会发现有刚才退出去的状态,如下:
# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS
c45469c019aa centos "/bin/bash" 12 minutes ago Exited (0) 7 seconds ago
使用以下命令,根据某个“容器 ID”来创建一个新的“镜像”:
docker commit c45469c019aa os7tom7jdk8:v1.0
然后就ok了
通过docker命令验证一下,
docker run -d -p 8080:8080 -v /root/webapps/:/opt/tomcat/webapps/ --name mytomcat_1 os7tom7jdk8:v1.0 /root/run.sh
- 安卓客户端下载
- 微信扫一扫
- 微信公众号
- 微信公众号扫一扫