docker制作tomcat镜像

准备cestos镜像、tomcat、jdk

cestos是docker pull下来的

在/opt/下创建docker:mkdir -p /opt/docker

把tomcat和jdk解压到docker目录下,分别命名为tomcat和jdk

删除jdk文件夹下多余文件, 降低build的镜像大小

rm -rf /z/docker/jdk/*src.zip \
/z/docker/jdk/lib/missioncontrol \
/z/docker/jdk/lib/visualvm \
/z/docker/jdk/lib/*javafx* \
/z/docker/jdk/jre/lib/plugin.jar \
/z/docker/jdk/jre/lib/ext/jfxrt.jar \
/z/docker/jdk/jre/bin/javaws \
/z/docker/jdk/jre/lib/javaws.jar \
/z/docker/jdk/jre/lib/desktop \
/z/docker/jdk/jre/plugin \
/z/docker/jdk/jre/lib/deploy* \
/z/docker/jdk/jre/lib/*javafx* \
/z/docker/jdk/jre/lib/*jfx* \
/z/docker/jdk/jre/lib/amd64/libdecora_sse.so \
/z/docker/jdk/jre/lib/amd64/libprism_*.so \
/z/docker/jdk/jre/lib/amd64/libfxplugins.so \
/z/docker/jdk/jre/lib/amd64/libglass.so \
/z/docker/jdk/jre/lib/amd64/libgstreamer-lite.so \
/z/docker/jdk/jre/lib/amd64/libjavafx*.so \
/z/docker/jdk/jre/lib/amd64/libjfx*.so

创建Dockerfile文件

#使用docker cestOs镜像
FROM docker.io/centos #作者信息
MAINTAINER guuyoog <gy>
LABEL Description="This image is used to serve tomcat 8 whit jdk8" Version="1.0" #在镜像中创建目录
#把jdk和tomcat添加到里面
RUN mkdir -p /opt/jdk1..0_181
ADD jdk /opt/jdk1..0_181 RUN mkdir -p /opt/tomcat-8.5.
ADD tomcat /opt/tomcat-8.5. #添加环境变量
ENV JAVA_HOME /opt/jdk1..0_181
ENV CATALINA_HOME /opt/tomcat-8.5.
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin ENV JAVA_OPTS "$JAVA_OPTS -server -XX:+UseParallelOldGC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/tomcat-8.5.32/dump/dump.hprof -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:/opt/tomcat-8.5.32/dump/heap_trace.txt -Duser.timezone=GMT+08"
#工作区域
WORKDIR /opt/tomcat-8.5. #暴露端口
EXPOSE #启动时运行tomcat
CMD ["catalina.sh", "run"]

开始构建docker镜像文件

docker build -t guuyoog/centos-jdk8-tomcat8:1.0 .
-t 设置tag名称, 命名规则registry/image:tag
. 表示使用当前目录下的Dockerfile文件

如果没有问题的话docker images能查看到新建的镜像

导出镜像 docker save -o jdk8-tomcat8.tar  <镜像ID>

导入镜像 docker load < jdk8-tomcat8.tar

docker images时可能会看不到REPOSITORY 和 tag,则用docker tag 639d56a4231a taomeng/jdk8-tomcat8:1.0赋值

创建容器

sudo docker run -it --name tomcat \
--net=host \
-p : \
-m 1024m \ #设置容器使用内存最大值;
--restart=always \ #重启机制
--privileged=true \ #使用该参数,container内的root拥有真正的root权限
-v /opt/tomcat/setenv.sh:/opt/tomcat-8.5./bin/setenv.sh \
-v /opt/tomcat/tomcat-users.xml:/opt/tomcat-8.5./conf/tomcat-users.xml \
-v /opt/tomcat/server.xml:/opt/tomcat-8.5./conf/server.xml \
-v /opt/tomcat/logs:/opt/tomcat-8.5./logs \
-v /opt/tomcat/output:/opt/tomcat-8.5./output \
-v /opt/tomcat/webapps:/opt/tomcat-8.5./webapps \
-v /opt/tomcat/dump:/opt/tomcat-8.5./dump \
-d taomeng/jdk8-tomcat8:1.0

docker update -m 2048m --memory-swap 2048m 修改容器内存

上一篇:[matlab] 5.字符运算与微积分


下一篇:【应用安全】微软的安全开发生命周期(SDL)