欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2020年09月14日 10:37:07   作者:calong  
這篇文章主要介紹了Docker批量容器編排的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

簡介

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

三個步驟:

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

初體驗

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: #服務列表
  service1:
    #服務配置
    container_name: #容器名稱
    depends_on: #依賴列表
    - depend1
    - depend2
    images: #鏡像
    - image1
    - image2
    build:. #構(gòu)建目錄
    network: #網(wǎng)絡
    ......
  service2: test2
    ......
volumnes: #掛載目錄列表
networks: #網(wǎng)絡列表
configs: #其他配置

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

相關(guān)文章

  • Docker容器中運行nginx

    Docker容器中運行nginx

    本文介紹了從docker hub拉取官方nginx鏡像并自定義部分配置,綁定端口運行的過程。希望小伙伴們能夠從中得到些知識
    2017-03-03
  • Docker部署用Python編寫的Web應用的實踐

    Docker部署用Python編寫的Web應用的實踐

    本文主要介紹了Docker部署用Python編寫的Web應用,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • docker?build與Dockerfile問題

    docker?build與Dockerfile問題

    這篇文章主要介紹了docker?build與Dockerfile問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Docker如何搭建私有鏡像倉庫

    Docker如何搭建私有鏡像倉庫

    這篇文章主要介紹了Docker如何搭建私有鏡像倉庫問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • docker啟動ES內(nèi)存溢出的解決方案

    docker啟動ES內(nèi)存溢出的解決方案

    這篇文章主要介紹了docker啟動ES內(nèi)存溢出的解決方案,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • Docker構(gòu)建ELK Docker集群日志收集系統(tǒng)

    Docker構(gòu)建ELK Docker集群日志收集系統(tǒng)

    為了在Docker集群中更好的管理查看日志 我們使用Docker 來搭建集群的ELK日志收集系統(tǒng),這篇文章介紹了Docker構(gòu)建ELK Docker集群日志收集系統(tǒng)的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • win10家庭版安裝Docker的方法步驟

    win10家庭版安裝Docker的方法步驟

    這篇文章主要介紹了win10家庭版安裝Docker的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-09-09
  • Docker File創(chuàng)建鏡像失敗ERROR [3/4] RUN yum -y install vim的解決

    Docker File創(chuàng)建鏡像失敗ERROR [3/4] RUN yum&nbs

    文章描述了在使用DockerFile創(chuàng)建基于CentOS Linux 8的鏡像時遇到的問題,即無法下載vim軟件包的元數(shù)據(jù),問題的原因是CentOS Linux 8的AppStream倉庫沒有可用的URL,為了解決這個問題,作者建議將CentOS版本修改為7,因為CentOS Linux 7的AppStream倉庫通常有可用的URL
    2024-11-11
  • docker容器如何指定utf-8編碼

    docker容器如何指定utf-8編碼

    這篇文章主要介紹了docker容器如何指定utf-8編碼問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • 詳解如何在 Docker 中設置 Go 并部署應用

    詳解如何在 Docker 中設置 Go 并部署應用

    在本教程中,我們將學習如何使用 docker 部署 golang web 應用程序。 具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-03-03

最新評論