利用Docker的commit命令制作镜tomcat像

1.查看基础镜像

[root@host152 myfile]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
redis         latest    aa4d65e670d6   8 days ago     105MB
hello-world   latest    d1165f221234   4 months ago   13.3kB
centos        latest    300e315adb2f   7 months ago   209MB

2.启动容器

[root@host152 ~]# docker run -itd --name centos-docker centos /bin/bash

3.拷贝tomcat和jdk到容器

[root@host152 myfile]# docker cp apache-tomcat-7.0.47.tar.gz centos-docker:/root
[root@host152 myfile]# docker cp jdk-8u161-linux-x64.tar.gz centos-docker:/root

4.登陆容器配置jdk和tomcat

登陆容器

[root@host152 myfile]# docker exec -it centos-docker /bin/bash

解压jdk

[root@0966db9df33d ~]# tar -zxvf jdk-8u161-linux-x64.tar.gz -C /usr/local

配置jdk环境变量

[root@0966db9df33d jdk1.8.0_161]# vi /etc/profile 
export JAVA_HOME=/usr/local/jdk1.8.0_161
export PATH=$JAVA_HOME/bin:$PATH

[root@0966db9df33d jdk1.8.0_161]# source /etc/profile
[root@0966db9df33d jdk1.8.0_161]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

解压tomcat
[root@0966db9df33d ~]# tar -zxvf apache-tomcat-7.0.47.tar.gz -C /usr/local

修改tomcat环境变量
[root@0966db9df33d bin]# vi /usr/local/apache-tomcat-7.0.47/bin/setclasspath.sh 
export JAVA_HOME=/usr/local/jdk1.8.0_161
export JRE_HOME=/usr/local/jdk1.8.0_161/jre

5.将正在运行的容器提交为一个新的镜像

提交镜像
[root@host152 myfile]# docker commit centos-docker centos-tomcat
sha256:2af8a6846aedcc6f880219c4df2494b8d8a7b87a581fb833f10c4a09a9b6accb

查看镜像
[root@host152 myfile]# docker images
REPOSITORY      TAG       IMAGE ID       CREATED          SIZE
centos-tomcat   latest    2af8a6846aed   29 seconds ago   805MB
redis           latest    aa4d65e670d6   9 days ago       105MB
hello-world     latest    d1165f221234   4 months ago     13.3kB
centos          latest    300e315adb2f   7 months ago     209MB

6.启动镜像和访问镜像

将制作的镜像提交为容器

[root@host152 myfile]# docker run -itd --name=centos-tomcat-run -p 8888:8080 centos-tomcat /bin/bash

报错
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program

        因为docker默认加载的配置文件是bashrc下面的所以配置修改bashrc添加jdk环境变量[root@1c3082e98bc5 /]# vi ~/.bashrc
export JAVA_HOME=/usr/local/jdk1.8.0_161
export PATH=$JAVA_HOME/bin:$PATH
[root@1c3082e98bc5 /]# source ~/.bashrc

        编辑tomcat下面的bin/startup.sh,加上初始化环境变量文件,再启动即可。

[root@1c3082e98bc5 bin]# vi startup.sh
source ~/.bashrc

        上述环境变量修改后,再次启动tomcat,访问8888端口,访问出现下图成功则说明镜像制作成功。 

利用Docker的commit命令制作镜tomcat像

上一篇:Qt开发经验小技巧161-165


下一篇:161 Scala 元组