香港云主机最佳企业级服务商!

ADSL拨号VPS包含了中国大陆(联通,移动,电信,)

中国香港,国外拨号VPS。

当前位置:云主机 > 服务器资讯 >

电信ADSL拨号VPS
联通ADSL拨号VPS
移动ADSL拨号VPS

Docker批量容器编排的实现


时间:2020-10-17 17:53 作者:admin


简介

Dockerfile build run 是手动操作单个容器,假如使用微服务架构,需要启动 100 + 个容器,他们之间的依赖关系如何维护?
Docker Compose 用来轻松高效地管理容器,定义运行多个容器。

三个步骤:

Dockerfile Services & docker-compose.yml docker-compose up

初体验

1.Dockerfile

FROM python/' target='_blank'>python:3.7-alpineWORKDIR /codeENV FLASK_APP app.pyENV FLASK_RUN_HOST 0.0.0.0RUN apk add --no-cache gcc musl-dev linux-headersCOPY requirements.txt requirements.txtRUN pip install -r requirements.txtCOPY . .CMD ["flask", "run"]

2.Service

import timeimport redisfrom flask import Flaskapp = Flask(__name__)cache = redis.Redis(host='redis', port=6379)def get_hit_count():  retries = 5  while True:    try:      return cache.incr('hits')    except redis.exceptions.ConnectionError as exc:      if retries == 0:        raise exc      retries -= 1      time.sleep(0.5)@app.route('/')def hello():  count = get_hit_count()  return 'Hello World! I have been seen {} times.\n'.format(count)

docker-compose.yml

version: '3'services:web: build: . ports:- "5000:5000" volumes:- .:/code - logvolume01:/var/log links:- redisredis: image: redisvolumes:logvolume01: {}docker-compose upStarting compose-demo_web_1  ... doneStarting compose-demo_redis_1 ... doneAttaching to compose-demo_redis_1, compose-demo_web_1redis_1 | 1:C 12 Sep 2020 07:34:09.654 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Ooredis_1 | 1:C 12 Sep 2020 07:34:09.655 # Redis version=6.0.7, bits=64, commit=00000000, modified=0, pid=1, just startedredis_1 | 1:C 12 Sep 2020 07:34:09.655 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.confredis_1 | 1:M 12 Sep 2020 07:34:09.657 * Running mode=standalone, port=6379.redis_1 | 1:M 12 Sep 2020 07:34:09.657 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.redis_1 | 1:M 12 Sep 2020 07:34:09.657 # Server initializedredis_1 | 1:M 12 Sep 2020 07:34:09.658 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.redis_1 | 1:M 12 Sep 2020 07:34:09.658 * Loading RDB produced by version 6.0.7redis_1 | 1:M 12 Sep 2020 07:34:09.658 * RDB age 156 secondsredis_1 | 1:M 12 Sep 2020 07:34:09.658 * RDB memory usage when created 0.77 Mbredis_1 | 1:M 12 Sep 2020 07:34:09.658 * DB loaded from disk: 0.000 secondsweb_1  | * Serving Flask app "app.py"web_1  | * Environment: productionweb_1  |  WARNING: This is a development server. Do not use it in a production deployment.web_1  |  Use a production WSGI server instead.web_1  | * Debug mode: offYML 文件规则version: "1.0" #版本services: #服务列表  service1:    #服务配置    container_name: #容器名称    depends_on: #依赖列表    - depend1    - depend2    images: #镜像    - image1    - image2    build:. #构建目录    network: #网络    ......  service2: test2    ......volumnes: #挂载目录列表networks: #网络列表configs: #其他配置

到此这篇关于Docker批量容器编排的实现的文章就介绍到这了,更多相关Docker批量容器编排内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

(责任编辑:admin)






帮助中心
会员注册
找回密码
新闻中心
快捷通道
域名登录面板
虚机登录面板
云主机登录面板
关于我们
关于我们
联系我们
联系方式

售前咨询:17830004266(重庆移动)

企业QQ:383546523

《中华人民共和国工业和信息化部》 编号:ICP备00012341号

Copyright © 2002 -2018 香港云主机 版权所有
声明:香港云主机品牌标志、品牌吉祥物均已注册商标,版权所有,窃用必究

云官方微信

在线客服

  • 企业QQ: 点击这里给我发消息
  • 技术支持:383546523

  • 公司总台电话:17830004266(重庆移动)
  • 售前咨询热线:17830004266(重庆移动)