Docker批量
容器编排的实现
本文详细介绍了Docker批量容器编辑的完成。原文根据示例代码非常详细,对大家的学习或者工作都有一定的参考价值。有需要的朋友会陪我一起学习。
简介
Dockerfile构建运行是手动 *** 作的单个容器。如果应用微服务架构,必须启动100个容器。如何维护他们的依赖关系?
DockerCompose用于轻松高效地管理方法容器,定义几个可以工作的容器。
三个过程:
构建
服务与营销。docker-compose.yml
docker-排版
初尝
1.Dockerfile
FROMpython:3.7-alpine
WORKDIR/code
ENVFLASK_APPapp.py
ENVFLASK_RUN_HOST0.0.0.0
RUNapkadd--no-cachegccmusl-devlinux-headers
COPYrequirements.txtrequirements.txt
RUNpipinstall-rrequirements.txt
COPY..
CMD["flask","run"]
2.服务
importtime
importredis
fromflaskimportFlask
app=Flask(__name__)
cache=redis.Redis(host='redis',port=6379)
defget_hit_count():
retries=5
whileTrue:
try:
returncache.incr('hits')
exceptredis.exceptions.ConnectionErrorasexc:
ifretries==0:
raiseexc
retries-=1
time.sleep(0.5)
@app.route('/')
defhello():
count=get_hit_count()
return'HelloWorld!Ihavebeenseen{}times.\n'.format(count)
docker-compose.yml
version:'3'
services:
web:
build:.
ports:
-"5000:5000"
volumes:
-.:/code
-logvolume01:/var/log
links:
-redis
redis:
image:redis
volumes:
logvolume01:{}
docker-composeup
Startingcompose-demo_web_1...done
Startingcompose-demo_redis_1...done
Attachingtocompose-demo_redis_1,compose-demo_web_1
redis_1|1:C12Sep202007:34:09.654#oO0OoO0OoO0OoRedisisstartingoO0OoO0OoO0Oo
redis_1|1:C12Sep202007:34:09.655#Redisversion=6.0.7,bits=64,commit=00000000,modified=0,pid=1,juststarted
redis_1|1:C12Sep202007:34:09.655#Warning:noconfigfilespecified,usingthedefaultconfig.Inordertospecifyaconfigfileuseredis-server/path/to/redis.conf
redis_1|1:M12Sep202007:34:09.657*Runningmode=standalone,port=6379.
redis_1|1:M12Sep202007:34:09.657#WARNING:TheTCPbacklogsettingof511cannotbeenforcedbecause/proc/sys/net/core/somaxconnissettothelowervalueof128.
redis_1|1:M12Sep202007:34:09.657#Serverinitialized
redis_1|1:M12Sep202007:34:09.658#WARNINGovercommit_memoryissetto0!Backgroundsavemayfailunderlowmemorycondition.Tofixthisissueadd'vm.overcommit_memory=1'to/etc/sysctl.confandthenrebootorrunthecommand'sysctlvm.overcommit_memory=1'forthistotakeeffect.
redis_1|1:M12Sep202007:34:09.658*LoadingRDBproducedbyversion6.0.7
redis_1|1:M12Sep202007:34:09.658*RDBage156seconds
redis_1|1:M12Sep202007:34:09.658*RDBmemoryusagewhencreated0.77Mb
redis_1|1:M12Sep202007:34:09.658*DBloadedfromdisk:0.000seconds
web_1|*ServingFlaskapp"app.py"
web_1|*Environment:production
web_1|WARNING:Thisisadevelopmentserver.Donotuseitinaproductiondeployment.
web_1|UseaproductionWSGIserverinstead.
web_1|*Debugmode:off
YML文档标准
version:"1.0"#版本号
services:#服务项目目录
service1:
#服务项目配备
container_name:#容器名字
depends_on:#依靠目录
-depend1
-depend2
images:#镜像系统
-image1
-image2
build:.#搭建文件目录
network:#互联网
......
service2:test2
......
volumnes:#初始化文件目录目录
networks:#互联网目录
configs:#别的配备
至此,这篇关于Docker的海量容器编辑完成的文章已经在这里详细介绍过了。有关Docker的海量容器编辑的大量内容,请搜索您以前的文章或再次访问下面的相关文章。期待你以后的申请!
评论列表(0条)