Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1426167
  • 博文数量: 188
  • 博客积分: 1784
  • 博客等级: 上尉
  • 技术积分: 2772
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-05 22:20
个人简介

发上等愿,结中等缘,享下等福;择高处立,就平处坐,向宽处行。

文章分类

全部博文(188)

文章存档

2020年(12)

2019年(11)

2018年(4)

2017年(3)

2016年(11)

2015年(22)

2014年(19)

2013年(25)

2012年(32)

2011年(49)

分类: 虚拟化

2019-08-28 13:10:43

执行生成镜像命令
docker build -t tomcat7:7.0.61 . 镜像名:版本号
根据镜像生成容器
docker run -dit --name resource resoure:1.0
查看容器是否启动成功日志
docker logs -f resource

1、activemq/dockerfile
# build activemq
FROM centos:latest
MAINTAINER wangyanlong@sina.cn
RUN yum -y install curl net-tools
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
# install jdk
ADD ./jdk-7u79-linux-x64.gz /usr/local
ENV JAVA_HOME=/usr/local/jdk1.7.0_79
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
# install activemq
ADD ./activemq-01 /usr/local/activemq-01
RUN chmod +x /usr/local/activemq-01/bin/*
EXPOSE 8161
EXPOSE 61616
ENTRYPOINT /usr/local/activemq-01/bin/activemq start && tail -F /usr/local/activemq-01/data/activemq.log

2、elasticsearch/dockerfile
# build elasticsearch
FROM centos:latest
MAINTAINER wangyanlong@sina.cn
RUN yum -y install curl net-tools
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#install JDK
ADD ./jdk-7u79-linux-x64.gz /usr/local
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
ENV JAVA_HOME=/usr/local/jdk1.7.0_79
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
# install elasticsearch
ADD ./elasticsearch-rtf-2.2.1 /usr/local/elasticsearch-rtf-2.2.1
RUN chmod +x /usr/local/elasticsearch-rtf-2.2.1/bin/*
EXPOSE 9200
EXPOSE 9300
ENTRYPOINT /usr/local/elasticsearch-rtf-2.2.1/bin/elasticsearch -Des.insecure.allow.root=true -d && tail -F /usr/local/elasticsearch-rtf-2.2.1/logs/elasticsearch.log

3、tomcat/dockerfile
#images of apache
FROM centos:latest
MAINTAINER wangyanlong@sina.cn
RUN yum -y install curl net-tools
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#install JDK
ADD ./jdk-7u79-linux-x64.gz /usr/local
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
ENV JAVA_HOME=/usr/local/jdk1.7.0_79
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
#install tomcat
ADD ./apache-tomcat-7.0.61 /usr/local/apache-tomcat-7.0.61
RUN chmod +x /usr/local/apache-tomcat-7.0.61/bin/*
EXPOSE 8080
ENTRYPOINT /usr/local/apache-tomcat-7.0.61/bin/startup.sh && tail -F /usr/local/apache-tomcat-7.0.61/logs/catalina.out

4、tomcatffmpeg/dockerfile
#images of apache
FROM centos:latest
MAINTAINER yuguangwei@test.cn
RUN yum -y install curl net-tools gcc make
#install ffmpeg
ADD ./ffmpeg-3.3.1.tar.bz2 /usr/local/
RUN cd /usr/local/ffmpeg-3.3.1 && ./configure --disable-yasm && make && make install
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#install JDK
ADD ./jdk-7u79-linux-x64.gz /usr/local
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
ENV JAVA_HOME=/usr/local/jdk1.7.0_79
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
#install tomcat
ADD ./apache-tomcat-7.0.61 /usr/local/apache-tomcat-7.0.61
RUN chmod +x /usr/local/apache-tomcat-7.0.61/bin/*
EXPOSE 8080
ENTRYPOINT /usr/local/apache-tomcat-7.0.61/bin/startup.sh && tail -F /usr/local/apache-tomcat-7.0.61/logs/catalina.out

5、cache/dockerfile
# build cache
FROM centos:latest
MAINTAINER yuguangwei@test.cn
RUN yum -y install curl net-tools
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#install JDK
ADD ./jdk-7u79-linux-x64.gz /usr/local
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
ENV JAVA_HOME=/usr/local/jdk1.7.0_79
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
# install cache
ADD ./cache-worker /usr/local/cache-worker
RUN chmod +x /usr/local/cache-worker/*
ENTRYPOINT /usr/local/cache-worker/analysis-cache-worker.sh start test && tail -F /usr/local/cache-worker/test/logs

6、nginx/dockerfile
#images of apache
FROM centos:latest
MAINTAINER yuguangwei@test.cn
RUN yum -y install curl net-tools
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
#install nginx
RUN yum -y install gcc gcc-c++ make auotmake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel
ADD ./nginx-1.6.2.tar.gz /usr/local
#COPY /usr/local/ygw/nginx-1.6.2.tar.gz /usr/
RUN cd /usr/local/nginx-1.6.2 && ./configure --prefix=/usr/local/nginx --with-http_stub_status_module && make &&make install
EXPOSE 80
#ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -F /usr/local/nginx/logs/access.log

7、cat redis/dockerfile
#build redis
FROM centos:latest
MAINTAINER yuguangwei@jetsen.cn
RUN yum -y install curl net-tools gcc tcl make
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
# install redis
RUN mkdir /usr/local/redis
ADD redis-3.0.0-rc5.tar.gz /usr/local/src/
#RUN cd /usr/local/src/ && mv redis-3.0.0-rc5 redis3.0
RUN cd /usr/local/src/redis-3.0.0-rc5 && make PREFIX=/usr/local/redis install && cd src/ && make install
ADD redis /etc/rc.d/init.d/redis
RUN chmod +x /etc/rc.d/init.d/redis
ADD 6379.conf /usr/local/redis/conf/6379.conf
EXPOSE 6379
ENTRYPOINT /etc/init.d/redis start

8、zookeeper/dockerfile
# build zookeeper
FROM centos:latest
MAINTAINER yuguangwei@test.cn
RUN yum -y install curl net-tools
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#install JDK
ADD ./jdk-7u79-linux-x64.gz /usr/local
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
ENV JAVA_HOME=/usr/local/jdk1.7.0_79
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
# install zookeeper
ADD ./node-01 /usr/local/node-01
RUN chmod +x /usr/local/node-01/bin/*
ENTRYPOINT /usr/local/node-01/bin/zkServer.sh start && tail -F /zookeeper.out

9、comment/dockerfile
#images of apache
FROM centos:latest
MAINTAINER yuguangwei@test.cn
RUN yum -y install curl net-tools
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#install JDK
ADD ./jdk-8u111-linux-x64.tar.gz /usr/local
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
ENV JAVA_HOME=/usr/local/jdk1.8.0_111
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
#install comment
RUN mkdir /usr/local/comment
ADD ./edu-cloud-service-comment.jar /usr/local/comment
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/comment/edu-cloud-service-comment.jar"]

10、eureka/dockerfile
#images of apache
FROM centos:latest
MAINTAINER yuguangwei@test.cn
RUN yum -y install curl net-tools
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#install JDK
ADD ./jdk-8u111-linux-x64.tar.gz /usr/local
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
ENV JAVA_HOME=/usr/local/jdk1.8.0_111
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
#install eureka
RUN mkdir /usr/local/eureka
ADD ./edu-cloud-eureka.jar /usr/local/eureka
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/eureka/edu-cloud-eureka.jar"]

11、guidance/dockerfile
#images of apache
FROM centos:latest
MAINTAINER yuguangwei@test.cn
RUN yum -y install curl net-tools
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#install JDK
ADD ./jdk-8u111-linux-x64.tar.gz /usr/local
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
ENV JAVA_HOME=/usr/local/jdk1.8.0_111
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
#install comment
RUN mkdir /usr/local/guidance
ADD ./edu-cloud-service-guidance-learning.jar /usr/local/guidance
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/guidance/edu-cloud-service-guidance-learning.jar"]

12、jdk-service/dockerfile
# build elasticsearch
FROM centos:latest
MAINTAINER yuguangwei@test.cn
RUN yum -y install curl net-tools
#geng gai shi qu
RUN rm -rf /etc/localtime
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#install JDK
ADD ./jdk-8u161-linux-x64.rpm /usr/local
#zh_CN
RUN yum install -y kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL=zh_CN.utf8
RUN rpm -ivh /usr/local/jdk-8u161-linux-x64.rpm
ADD ./spring-boot.sh /root
RUN chmod +x /root/spring-boot.sh
ENTRYPOINT ["./root/spring-boot.sh","start"]

容器启动jdk-service/spring-boot.sh
#!/bin/bash

SpringBoot=$NAME_ENV

if [ "$1" = "" ];
then
echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
exit 1
fi

if [ "$SpringBoot" = "" ];
then
echo -e "\033[0;31m 未输入应用名 \033[0m"
exit 1
fi

function start()
{
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
if [ $count != 0 ];then
echo "$SpringBoot is running..."
else
echo "Start $SpringBoot success..."
java -jar $SpringBoot
fi
}

function stop()
{
echo "Stop $SpringBoot"
boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`

if [ $count != 0 ];then
kill $boot_id
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`

boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
kill -9 $boot_id
fi
}

function restart()
{
stop
sleep 2
start
}

function status()
{
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
if [ $count != 0 ];then
echo "$SpringBoot is running..."
else
echo "$SpringBoot is not running..."
fi
}

case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)

echo -e "\033[0;31m Usage: \033[0m \033[0;34m sh $0 {start|stop|restart|status} {SpringBootJarName} \033[0m
\033[0;31m Example: \033[0m
\033[0;33m sh $0 start esmart-test.jar \033[0m"
esac

创建集群网络edu
docker network create -d overlay edu
执行命令生成容器 update也是用这个
docker stack deploy -c compose.yml db
删除容器
docker stack rm db
查看容器服务
docker service ls

1、业务逻辑compose.yml

version: "3"
services:
user:
image: 192.168.9.95/base/tomcat:7.0.61
hostname: user
ports:
- "7000:8080"
volumes:
- /srv/jetsen/user:/user
- usertomcat:/usr/local/apache-tomcat-7.0.61/
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud3_122
jecc:
image: 192.168.9.95/base/tomcat:7.0.61
hostname: jecc
ports:
- "8300:8080"
volumes:
- /srv/jetsen/jecc:/jecc
- jecctomcat:/usr/local/apache-tomcat-7.0.61/
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud3_122
classcard:
image: 192.168.9.95/base/tomcat:7.0.61
hostname: classcard
ports:
- "6900:8080"
volumes:
- /srv/jetsen/classcard:/classcard
- classcardtomcat:/usr/local/apache-tomcat-7.0.61/
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud4_123
course:
image: 192.168.9.95/base/tomcat:7.0.61
hostname: course
ports:
- "7703:8080"
volumes:
- /srv/jetsen/course:/course
- coursetomcat:/usr/local/apache-tomcat-7.0.61/
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud4_123
guide:
image: 192.168.9.95/base/spring-boot-jdk:1.8_161
hostname: guide
ports:
- "8200:8200"
environment:
NAME_ENV: /usr/local/pargram/edu-cloud-service-guidance-learning.jar
volumes:
- /srv/jetsen/guide:/usr/local/pargram
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud3_122

comment:
image: 192.168.9.95/base/spring-boot-jdk:1.8_161
hostname: comment
ports:
- "7600:7600"
environment:
NAME_ENV: /usr/local/pargram/edu-cloud-service-comment.jar
volumes:
- /srv/jetsen/comment:/usr/local/pargram
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud3_122

resource:
image: 192.168.9.95/base/spring-boot-jdk:1.8_161
hostname: resource
ports:
- "7400:7400"
environment:
NAME_ENV: /usr/local/pargram/edu-cloud-service-resource.jar
volumes:
- /srv/jetsen/resource:/usr/local/pargram
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud2_121

oss:
image: 192.168.9.95/base/spring-boot-jdk:1.8_161
hostname: oss
ports:
- "8100:8100"
environment:
NAME_ENV: /usr/local/pargram/edu-cloud-oss.jar
volumes:
- /srv/jetsen/oss:/usr/local/pargram
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud2_121
nginx:
image: nginx:1.15
hostname: nginx
ports:
- "8888:80"
volumes:
- nginxconf:/etc/nginx
- nginxhtml:/usr/share/nginx
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud2_121
space:
image: 192.168.9.95/base/spring-boot-jdk:1.8_161
hostname: space
ports:
- "8900:8900"
environment:
NAME_ENV: /usr/local/pargram/edu-cloud-space.jar
volumes:
- /srv/jetsen/space:/usr/local/pargram
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud2_121
edu:
image: 192.168.9.95/base/spring-boot-jdk:1.8_161
hostname: edu
ports:
- "7200:7200"
environment:
NAME_ENV: /usr/local/pargram/edu-cloud-edu.jar
volumes:
- /srv/jetsen/edu:/usr/local/pargram
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == cloud2_121
volumes:
usertomcat:
jecctomcat:
classcardtomcat:
nginxconf:
nginxhtml:
coursetomcat:
networks:
default:
jetsen:
external: true

2、数据库db的compose.yml
version: "3"
services:
mysql:
image: mysql:5.7
hostname: mysql
ports:
- "9100:3306"
environment:
- "MYSQL_ROOT_PASSWORD=root"
volumes:
- /srv/jetsen/mysql:/mysql
- mysqldata:/var/lib/mysql
- mysqlconf:/etc/mysql
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == x2

redis:
image: jetsen:redis
hostname: redis
ports:
- "9200:6379"
volumes:
- /srv/jetsen/redis:/redis
- redisdata:/usr/local/redis/conf
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == x2

elasticsearch:
image: jetsen:elasticsearch
hostname: elasticsearch
ports:
- "9301:9200"
- "9300:9300"
environment:
ES_HEAP_SIZE: 1g
volumes:
- /srv/jetsen/elasticsearch:/elasticsearch
- eladata:/usr/local/elasticsearch-rtf-2.2.1/data
- elaconfig:/usr/local/elasticsearch-rtf-2.2.1/config
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == x2

rabbitmq:
image: rabbitmq:management
hostname: rabbitmq
ports:
- "15672:15672"
- "5672:5672"
- "25672:25672"
- "61613:61613"
- "1883:1883"
environment:
RABBITMQ_DEFAULT_USER: admin
RABBITMQ_DEFAULT_PASS: admin
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == x2
activemq:
image: webcenter/activemq:5.14.3
hostname: activemq
ports:
- "9400:8161"
- "9401:61616"
- "9402:61613"
environment:
ACTIVEMQ_ADMIN_LOGIN: admin
ACTIVEMQ_ADMIN_PASSWORD: admin
volumes:
- activemqdata:/data
- activemqlog:/var/log/activemq
networks:
- jetsen
deploy:
placement:
constraints:
- engine.labels.function == x2
volumes:
redisdata:
eladata:
elaconfig:
mysqldata:
mysqlconf:
activemqdata:
activemqlog:


networks:
default:
jetsen:
external: true

阅读(4798) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~