@zhaikun
2017-09-02T18:24:53.000000Z
字数 2801
阅读 1212
docker
1、RC类型tomcat基础镜像
#1、编写yaml文件
apiVersion: v1 #api版本 固定
kind: ReplicationController #kind类型ReplicationController
metadata:
name: zk-web
spec: #spec.selector是RC的pod选择器,spec.selector是RC的pod选择器,确保当前集群上始终有且仅有replicas个pod实例运行,这里我们spec.replicas=1表示只能运行一个(名为的zk-web)pod 实例
replicas: 1 #指启动几个副本
selector: #pod选择器
app: zk-web
template: #当集群中运行的pod数量小于replicas时,RC会根据spec.template 段定义的pod模版来生成一个新的pod实例,labels属性指定了该pod的标签,这里的labels必须匹配RC的spec.selecto
metadata:
labels:
app: zk-web
spec: #spec.image表示镜像地址。
containers:
- name: zk-web
image: harbor.suixingpay.com/study/tomcat-app:v2
ports: #表示容器服务的端口
- containerPort: 8080
env: #表示定义环境变量
- name: MYSQL_SERVICE_HOST
value: 'zk-mysql'
- name: MYSQL_SERVICE_PORT
value: '3306'
1、TOMCAT Docerfile
FROM harbor.suixingpay.com/study/centos:6.7
RUN yum install wget -y
RUN wget -O /etc/yum.repos.d/epel.repo http://172.16.132.241/epel/epel.repo
RUN wget -O /etc/yum.repos.d/CentOS-Base.repo http://172.16.132.241/centos/CentOS-Base.repo
RUN yum makecache fast
RUN yum install tar wget openssl openssh-server sudo -y
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
RUN echo "root:root" | chpasswd
##优化
RUN echo '* - nofile 65535 ' >>/etc/security/limits.conf
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# install JDK1.8
RUN wget http://172.16.132.241/soft/jdk/8u111/jdk-8u111-linux-x64.tar.gz
RUN tar zxvf jdk-8u111-linux-x64.tar.gz -C /opt
#RUN echo 'JAVA_HOME="/opt/jdk_1.8"' >>/etc/profile
#RUN echo 'CLASSPATH="$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib"'>>/etc/profile
#RUN echo 'PATH="$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin"' >>/etc/profile
ENV JAVA_HOME /opt/jdk1.8.0_111
ADD apache-tomcat-8.0.14.tar.gz /opt
RUN cd /opt/ && ls
EXPOSE 22
EXPOSE 8080
#RUN cd /opt/ && ls &&tar zxvf /opt/apache-tomcat-8.0.14.tar.gz
ENV CATALINA_HOME /opt/apache-tomcat-8.0.14
ENV PATH $PATH:$CATALINA_HOME/bin
ADD tomcat.sh /etc/init.d/tomcat
RUN chmod +x /etc/init.d/tomcat
#CMD ["/opt/tomcat.sh start"]
# /sbin/service sshd start
ENTRYPOINT /sbin/service sshd start && /sbin/service tomcat start && tail -f /opt/apache-tomcat-8.0.14/logs/catalina.out
#EXPOSE 22
#EXPOSE 8080
##tomcat.sh
export JAVA_HOME=/opt/jdk1.8.0_111
export TOMCAT_HOME=/opt/apache-tomcat-8.0.14
case $1 in
start)
sh $TOMCAT_HOME/bin/startup.sh
;;
stop)
sh $TOMCAT_HOME/bin/shutdown.sh
;;
restart)
sh $TOMCAT_HOME/bin/shutdown.sh
sh $TOMCAT_HOME/bin/startup.sh
;;
esac
exit 0
##生成镜像
[root@k8s-harbor01 tomcat]# docker build -t harbor.suixingpay.com/zhaikun/cent_tomcat:3.1 .
[root@k8s-harbor01 tomcat]# docker push harbor.suixingpay.com/zhaikun/cent_tomcat:3.1
2、RC类型基础镜像
apiVersion: v1
kind: ReplicationController
metadata:
name: zk-jdk-tomcat
spec:
replicas: 1
selector:
app: zk-jdk-tomcat
template:
metadata:
labels:
app: zk-jdk-tomcat
spec:
containers:
- name: zk-jdk-tomcat
image: harbor.suixingpay.com/zhaikun/cent_tomcat:3.1
ports:
- containerPort: 8080
1、SERVER类型基础镜像
apiVersion: v1
kind: Service
metadata:
name: zk-jdk-tomcat
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30009
selector:
app: zk-jdk-tomcat