1、制做JAVA运行环境镜像
我的基础镜像是基于官网centos 7.2版本制作,没有可以提前下载好
#docker pull docker.io/centos
[[email protected] ~]# mkdir -p /opt/Dockerfile/JRE1.7
[[email protected] ~]# cd /opt/Dockerfile/JRE1.7
[[email protected] jre1.7]# ls
Dockerfile server-jre-7u80-linux-x64.tar.gz
[[email protected] jre1.7]# cat Dockerfile
FROM centos:latest
MAINTAINER yy ENV JAVA_VERSION "7u80" ENV JDK_VERSION "1.7.0_80" RUN rpm --rebuilddb && yum --setopt=tsflags=nodocs -y install net-tools && rm -rf /var/cache/yum/* && yum clean all #RUN rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7 # && yum update && yum install net-tools -y RUN mkdir -p /usr/lib/jvm COPY server-jre-${JAVA_VERSION}-linux-x64.tar.gz /usr/lib/jvm/server-jre-${JAVA_VERSION}-linux-x64.tar.gz RUN cd /usr/lib/jvm && tar -zxvf server-jre-${JAVA_VERSION}-linux-x64.tar.gz && rm -rf /usr/lib/jvm/server-jre-${JAVA_VERSION}-linux-x64.tar.gz && ln -s /usr/lib/jvm/jdk${JDK_VERSION}/bin/java /bin/ && cd /usr/lib/jvm/jdk${JDK_VERSION} && find . -type f -name ‘*.html‘ -delete && find . -type f -name ‘COPYRIGHT‘ -delete && find . -type f -name ‘LICENSE‘ -delete && find . -type f -name ‘NOTICE‘ -delete && find . -type f -name ‘3RDPARTY‘ -delete && find . -type f -name ‘*.txt‘ -delete && find . -type f -name ‘*.bat‘ -delete #jre包可以再做精简
2.制作生产环境Tomcat镜像
[[email protected] ~]# mkdir -p /opt/Dockerfile/tomcat7
[[email protected] ~]# cd /opt/Dockerfile/tomcat7
[[email protected] tomcat7]# ls
apache-tomcat-7.0.70.tar.gz Dockerfile
[[email protected] tomcat7]# cat Dockerfile
FROM java7:7u80 MAINTAINER yy ENV TOMCAT_VERSION 7.0.70 ENV CATALINA_HOME /tomcat ENV APP_DIR ${CATALINA_HOME}/webapps/ RUN rpm --rebuilddb && yum --setopt=tsflags=nodocs -y install apr tomcat-native && rm -rf /var/cache/yum/* && yum clean all #RUN wget -q https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_MINOR_VERSION}/bin/apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz #https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.70/bin/apache-tomcat-7.0.70.tar.gz COPY apache-tomcat-${TOMCAT_VERSION}.tar.gz apache-tomcat-{TOMCAT_VERSION}.tar.gz RUN tar zxf apache-tomcat-*.tar.gz && rm apache-tomcat-*.tar.gz && mv apache-tomcat* tomcat && rm -rf tomcat/webapps/* && sed -i ‘/protocol="AJP\/1.3"/d‘ /tomcat/conf/server.xml EXPOSE 8080 ENTRYPOINT ["/tomcat/bin/catalina.sh","run"] ONBUILD ADD . ${APP_DIR}
制作镜像
[[email protected] tomcat7]#docker build -t tomcat7:7.0.70 .
从镜像启动一个tomcat容器,把测试程序部署到/www/app1/webapps下从浏览器访问
[[email protected] ]# docker run -d -p 8002:8080 --name mytomcat7 -v /www/app1/webapps/:/tomcat/webapps tomcat7:7.0.70
3.制作数据库mariadb镜像