濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > Docker批量容器編排的實(shí)現(xiàn)

Docker批量容器編排的實(shí)現(xiàn)

熱門標(biāo)簽:信貸電銷機(jī)器人系統(tǒng) 江蘇自動(dòng)外呼系統(tǒng)一般多少錢 山東電信外呼系統(tǒng)靠譜嗎 比較穩(wěn)定的外呼系統(tǒng) 長沙回?fù)芡夂粝到y(tǒng) 云南云電銷機(jī)器人招商 鸚鵡螺號(hào)航海地圖標(biāo)注時(shí)間 ai電話機(jī)器人營銷 400 電話 申請(qǐng)費(fèi)用

簡介

Dockerfile build run 是手動(dòng)操作單個(gè)容器,假如使用微服務(wù)架構(gòu),需要啟動(dòng) 100 + 個(gè)容器,他們之間的依賴關(guān)系如何維護(hù)?
Docker Compose 用來輕松高效地管理容器,定義運(yùn)行多個(gè)容器。

三個(gè)步驟:

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

初體驗(yàn)

1.Dockerfile

FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP app.py
ENV FLASK_RUN_HOST 0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["flask", "run"]

2.Service

import time
import redis
from flask import Flask
app = 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:
- redis
redis:
 image: redis
volumes:
logvolume01: {}
docker-compose up
Starting compose-demo_web_1  ... done
Starting compose-demo_redis_1 ... done
Attaching to compose-demo_redis_1, compose-demo_web_1
redis_1 | 1:C 12 Sep 2020 07:34:09.654 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 12 Sep 2020 07:34:09.655 # Redis version=6.0.7, bits=64, commit=00000000, modified=0, pid=1, just started
redis_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.conf
redis_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 initialized
redis_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.7
redis_1 | 1:M 12 Sep 2020 07:34:09.658 * RDB age 156 seconds
redis_1 | 1:M 12 Sep 2020 07:34:09.658 * RDB memory usage when created 0.77 Mb
redis_1 | 1:M 12 Sep 2020 07:34:09.658 * DB loaded from disk: 0.000 seconds
web_1  | * Serving Flask app "app.py"
web_1  | * Environment: production
web_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: off
YML 文件規(guī)則
version: "1.0" #版本
services: #服務(wù)列表
  service1:
    #服務(wù)配置
    container_name: #容器名稱
    depends_on: #依賴列表
    - depend1
    - depend2
    images: #鏡像
    - image1
    - image2
    build:. #構(gòu)建目錄
    network: #網(wǎng)絡(luò)
    ......
  service2: test2
    ......
volumnes: #掛載目錄列表
networks: #網(wǎng)絡(luò)列表
configs: #其他配置

到此這篇關(guān)于Docker批量容器編排的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Docker批量容器編排內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

標(biāo)簽:運(yùn)城 衡陽 拉薩 齊齊哈爾 亳州 澳門 烏海 嘉興

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Docker批量容器編排的實(shí)現(xiàn)》,本文關(guān)鍵詞  Docker,批量,容器,編排,的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Docker批量容器編排的實(shí)現(xiàn)》相關(guān)的同類信息!
  • 本頁收集關(guān)于Docker批量容器編排的實(shí)現(xiàn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    营山县| 扶余县| 呼伦贝尔市| 湛江市| 前郭尔| 楚雄市| 桂阳县| 西峡县| 汝阳县| 鞍山市| 江津市| 上蔡县| 疏勒县| 资溪县| 章丘市| 灵山县| 新龙县| 防城港市| 安泽县| 嘉鱼县| 博湖县| 太保市| 东城区| 河东区| 固原市| 石景山区| 呼伦贝尔市| 南江县| 枞阳县| 衡水市| 永胜县| 丽江市| 林芝县| 麻栗坡县| 平潭县| 松阳县| 岚皋县| 临漳县| 沛县| 农安县| 山东省|