最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Docker容器服務(wù)編排利器詳解

 更新時間:2022年07月01日 11:27:36   作者:孫和龔  
這篇文章主要介紹了Docker容器服務(wù)編排利器,主要包括使用使用Docker?Compose必要性及定義及一些Docker?Compose應(yīng)用參考資料,本文給大家介紹的非常詳細,需要的朋友可以參考下

一、使用Docker Compose必要性及定義

用容器運行一個服務(wù),需要使用docker run命令。但如果我要運行多個服務(wù)呢?

假設(shè)我要運行一個web服務(wù),還要運行一個db服務(wù),那么是用一個容器運行,還是用多個容器運行呢?

一個容器運行多個服務(wù)會造成鏡像的復(fù)雜度提高,docker傾向于一個容器運行一個應(yīng)用。

那么復(fù)雜的架構(gòu)就會需要很多的容器,并且需要它們之間有關(guān)聯(lián)(容器之間的依賴和連接)就更復(fù)雜了。

這個復(fù)雜的問題需要解決,這就涉及到了**容器編排**的問題了。

  • Compose
  • 編排
    • 是對多個容器進行啟動和管理的方法
    • 例如:LNMT,先啟動MySQL,再啟動Tomcat,最后啟動Nginx
  • 服務(wù)架構(gòu)的演進
  • 單體服務(wù)架構(gòu)
  • 分布式服務(wù)架構(gòu)
  • 微服務(wù)架構(gòu)
  • 超微服務(wù)架構(gòu)
  • 容器編排工具
  • docker machine
  • 在虛擬機中部署docker容器引擎的工具
  • docker compose
  • 是一個用于定義和運行多容器Docker的應(yīng)用程序工具
  • docker swarm
  • 是Docker Host主機批量管理及資源調(diào)度管理工具
  • mesos+marathon
  • mesos 對計算機計算資源進行管理和調(diào)度
  • marathon 服務(wù)發(fā)現(xiàn)及負載均衡的功能
  • kubernetes
  • google開源的容器編排工具

二、Docker Compose應(yīng)用參考資料

網(wǎng)址 https://docs.docker.com/compose/

  • yaml格式

https://yaml.org/

三、Docker Compose應(yīng)用最佳實踐步驟

3.1 概念

  • 工程(project)
  • 服務(wù) (Service)
  • 容器 (Container)

3.2 步驟

1.定義應(yīng)用的Dockerfile文件,為了anywhere進行構(gòu)建。

2.使用docker-compose.yaml定義一套服務(wù),這套服務(wù)可以一起在一個隔離環(huán)境中運行。

3.使用docker-compose up就可以啟動整套服務(wù)。

四、Docker Compose安裝

# wget https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64
# mv docker-compose-linux-x86_64 /usr/bin/docker-compose
# chmod +x /usr/bin/docker-compose
# docker-compose version
Docker Compose version v2.2.3

五、Docker Compose應(yīng)用案例

運行Python語言開發(fā)的網(wǎng)站

5.1 網(wǎng)站文件準備

# mkdir flaskproject
[root@localhost ~]# cd flaskproject/
[root@localhost flaskproject]#
[root@localhost flaskproject]# vim app.py
[root@localhost flaskproject]# cat app.py
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)
[root@localhost flaskproject]# vim requirements.txt
[root@localhost flaskproject]# cat requirements.txt
flask
redis

5.2 Dockerfile文件準備

[root@localhost flaskproject]# vim Dockerfile
[root@localhost flaskproject]# cat 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"]

5.3 Compose文件準備

[root@localhost flaskproject]# vim docker-compose.yaml
[root@localhost flaskproject]# cat docker-compose.yaml
version: '3'
services:
  web:
    build: .
    ports:
      - "5000:5000"
  redis:
    image: "redis:alpine"

5.4 使用docker-compose up啟動容器

[root@localhost flaskproject]# ls
app.py  docker-compose.yaml  Dockerfile  requirements.txt
[root@localhost flaskproject]# docker-compose up
輸出:
[+] Running 7/7
 ? redis Pulled                                                                         15.8s
   ? 59bf1c3509f3 Pull complete                                                          2.9s
   ? 719adce26c52 Pull complete                                                          3.0s
   ? b8f35e378c31 Pull complete                                                          5.8s
   ? d034517f789c Pull complete                                                          6.5s
   ? 3772d4d76753 Pull complete                                                          6.6s
   ? 211a7f52febb Pull complete                                                          6.8s
Sending build context to Docker daemon     714B
Step 1/9 : FROM python:3.7-alpine
3.7-alpine: Pulling from library/python
59bf1c3509f3: Already exists
07a400e93df3: Already exists
bdabb07397e1: Already exists
cd0af01c7b70: Already exists
d0f18e022200: Already exists
Digest: sha256:5a776e3b5336827faf7a1c3a191b73b5b2eef4cdcfe8b94f59b79cb749a2b5d8
Status: Downloaded newer image for python:3.7-alpine
 ---> e72b511ad78e
Step 2/9 : WORKDIR /code
 ---> Running in 2b9d07bef719
Removing intermediate container 2b9d07bef719
 ---> 7d39e96fadf1
Step 3/9 : ENV FLASK_APP app.py
 ---> Running in 9bcb28bd632a
Removing intermediate container 9bcb28bd632a
 ---> 79f656a616d5
Step 4/9 : ENV FLASK_RUN_HOST 0.0.0.0
 ---> Running in 8470c2dbd6c2
Removing intermediate container 8470c2dbd6c2
 ---> e212ba688fcd
Step 5/9 : RUN apk add --no-cache gcc musl-dev linux-headers
 ---> Running in 6e9ca0766bc8
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
(1/13) Installing libgcc (10.3.1_git20211027-r0)
(2/13) Installing libstdc++ (10.3.1_git20211027-r0)
(3/13) Installing binutils (2.37-r3)
(4/13) Installing libgomp (10.3.1_git20211027-r0)
(5/13) Installing libatomic (10.3.1_git20211027-r0)
(6/13) Installing libgphobos (10.3.1_git20211027-r0)
(7/13) Installing gmp (6.2.1-r1)
(8/13) Installing isl22 (0.22-r0)
(9/13) Installing mpfr4 (4.1.0-r0)
(10/13) Installing mpc1 (1.2.1-r0)
(11/13) Installing gcc (10.3.1_git20211027-r0)
(12/13) Installing linux-headers (5.10.41-r0)
(13/13) Installing musl-dev (1.2.2-r7)
Executing busybox-1.34.1-r3.trigger
OK: 143 MiB in 49 packages
Removing intermediate container 6e9ca0766bc8
 ---> 273d4f04dfbc
Step 6/9 : COPY requirements.txt requirements.txt
 ---> daf51c54e8ba
Step 7/9 : RUN pip install -r requirements.txt
 ---> Running in 2aa2d30c5311
Collecting flask
  Downloading Flask-2.0.3-py3-none-any.whl (95 kB)
Collecting redis
  Downloading redis-4.1.3-py3-none-any.whl (173 kB)
Collecting Jinja2>=3.0
  Downloading Jinja2-3.0.3-py3-none-any.whl (133 kB)
Collecting itsdangerous>=2.0
  Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting click>=7.1.2
  Downloading click-8.0.3-py3-none-any.whl (97 kB)
Collecting Werkzeug>=2.0
  Downloading Werkzeug-2.0.3-py3-none-any.whl (289 kB)
Collecting deprecated>=1.2.3
  Downloading Deprecated-1.2.13-py2.py3-none-any.whl (9.6 kB)
Collecting packaging>=20.4
  Downloading packaging-21.3-py3-none-any.whl (40 kB)
Collecting importlib-metadata>=1.0
  Downloading importlib_metadata-4.11.1-py3-none-any.whl (17 kB)
Collecting wrapt<2,>=1.10
  Downloading wrapt-1.13.3-cp37-cp37m-musllinux_1_1_x86_64.whl (78 kB)
Collecting typing-extensions>=3.6.4
  Downloading typing_extensions-4.1.1-py3-none-any.whl (26 kB)
Collecting zipp>=0.5
  Downloading zipp-3.7.0-py3-none-any.whl (5.3 kB)
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl (30 kB)
Collecting pyparsing!=3.0.5,>=2.0.2
  Downloading pyparsing-3.0.7-py3-none-any.whl (98 kB)
Installing collected packages: zipp, typing-extensions, wrapt, pyparsing, MarkupSafe, importlib-metadata, Werkzeug, packaging, Jinja2, itsdangerous, deprecated, click, redis, flask
Successfully installed Jinja2-3.0.3 MarkupSafe-2.0.1 Werkzeug-2.0.3 click-8.0.3 deprecated-1.2.13 flask-2.0.3 importlib-metadata-4.11.1 itsdangerous-2.0.1 packaging-21.3 pyparsing-3.0.7 redis-4.1.3 typing-extensions-4.1.1 wrapt-1.13.3 zipp-3.7.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.2.4; however, version 22.0.3 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Removing intermediate container 2aa2d30c5311
 ---> dd8f52b132f8
Step 8/9 : COPY . .
 ---> b36938a26cf5
Step 9/9 : CMD ["flask", "run"]
 ---> Running in 260cbfa02959
Removing intermediate container 260cbfa02959
 ---> fa04dfec6ff2
Successfully built fa04dfec6ff2
Successfully tagged flaskproject_web:latest

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
[+] Running 3/3
 ? Network flaskproject_default    Created                                               0.1s
 ? Container flaskproject-redis-1  Created                                               0.1s
 ? Container flaskproject-web-1    Created                                               0.1s
Attaching to flaskproject-redis-1, flaskproject-web-1
flaskproject-redis-1  | 1:C 15 Feb 2022 14:14:21.696 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
flaskproject-redis-1  | 1:C 15 Feb 2022 14:14:21.696 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1, just started
flaskproject-redis-1  | 1:C 15 Feb 2022 14:14:21.696 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
flaskproject-redis-1  | 1:M 15 Feb 2022 14:14:21.697 * monotonic clock: POSIX clock_gettime
flaskproject-redis-1  | 1:M 15 Feb 2022 14:14:21.698 * Running mode=standalone, port=6379.
flaskproject-redis-1  | 1:M 15 Feb 2022 14:14:21.698 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
flaskproject-redis-1  | 1:M 15 Feb 2022 14:14:21.698 # Server initialized
flaskproject-redis-1  | 1:M 15 Feb 2022 14:14:21.698 # 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.
flaskproject-redis-1  | 1:M 15 Feb 2022 14:14:21.698 * Ready to accept connections
flaskproject-web-1    |  * Serving Flask app 'app.py' (lazy loading)
flaskproject-web-1    |  * Environment: production
flaskproject-web-1    |    WARNING: This is a development server. Do not use it in a production deployment.
flaskproject-web-1    |    Use a production WSGI server instead.
flaskproject-web-1    |  * Debug mode: off
flaskproject-web-1    |  * Running on all addresses.
flaskproject-web-1    |    WARNING: This is a development server. Do not use it in a production deployment.
flaskproject-web-1    |  * Running on http://172.18.0.2:5000/ (Press CTRL+C to quit)

5.5 訪問

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

相關(guān)文章

  • docker私有倉庫Harbor配置

    docker私有倉庫Harbor配置

    本文主要介紹了在openEuler或rockylinux上配置docker私有倉庫Harbor,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-03-03
  • Docker Buildx構(gòu)建多平臺鏡像的實現(xiàn)

    Docker Buildx構(gòu)建多平臺鏡像的實現(xiàn)

    本文主要介紹了Docker Buildx構(gòu)建多平臺鏡像的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • 如何在一臺服務(wù)器上使用docker運行kafka集群

    如何在一臺服務(wù)器上使用docker運行kafka集群

    文章詳細介紹了如何在一臺服務(wù)器上使用Docker運行Kafka集群,包括拉取鏡像、創(chuàng)建網(wǎng)絡(luò)、啟動Kafka容器、檢查運行狀態(tài)、編寫啟動和關(guān)閉腳本、進入容器檢查、故障排查以及啟動生產(chǎn)者和消費者等步驟,感興趣的朋友跟隨小編一起看看吧
    2025-01-01
  • Docker?部署?Nexus?Maven私服的詳細過程

    Docker?部署?Nexus?Maven私服的詳細過程

    Nexus?是一個強大的倉庫管理器,廣泛用于管理和組織軟件構(gòu)建過程中的依賴項和構(gòu)件,通過?Docker?部署?Nexus?私服,可以簡化安裝和管理過程,并提供更高的靈活性和可擴展性,這篇文章主要介紹了Docker?部署?Nexus?Maven私服的詳細過程,需要的朋友可以參考下
    2024-08-08
  • Docker制作鏡像的兩種方式(在線制作和離線制作)

    Docker制作鏡像的兩種方式(在線制作和離線制作)

    我們知道要創(chuàng)建一個Docker容器,要先有Docker鏡像,Docker鏡像怎么創(chuàng)建的呢?下面這篇文章主要給大家介紹了關(guān)于Docker制作鏡像的兩種方式(在線制作和離線制作)的相關(guān)資料,需要的朋友可以參考下
    2023-03-03
  • Docker容器化應(yīng)用與結(jié)構(gòu)

    Docker容器化應(yīng)用與結(jié)構(gòu)

    本文詳細講解了Docker的容器化應(yīng)用與結(jié)構(gòu),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • Docker上部署?nps?和?npc?實現(xiàn)內(nèi)網(wǎng)穿透

    Docker上部署?nps?和?npc?實現(xiàn)內(nèi)網(wǎng)穿透

    本文介紹了如何使用Docker部署nps和npc實現(xiàn)內(nèi)網(wǎng)穿透。nps是一款高性能的內(nèi)網(wǎng)穿透代理服務(wù)器,npc是nps的客戶端,可以將內(nèi)網(wǎng)服務(wù)映射到公網(wǎng)上。通過Docker的容器化技術(shù),可以方便地部署和管理nps和npc,同時保證了應(yīng)用的隔離性和安全性。
    2023-04-04
  • Dockerfile多鏡像構(gòu)建方式

    Dockerfile多鏡像構(gòu)建方式

    這篇文章主要介紹了Dockerfile多鏡像構(gòu)建方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • centos修改docker網(wǎng)絡(luò)配置方法分享

    centos修改docker網(wǎng)絡(luò)配置方法分享

    本文給大家分享的是centos修改docker網(wǎng)絡(luò)配置的方法,非常的實用,有需要的小伙伴可以參考下
    2017-03-03
  • 使用docker compose安裝harbor私有倉庫的詳細教程

    使用docker compose安裝harbor私有倉庫的詳細教程

    harbor鏡像倉庫是由VMware開源的一款企業(yè)級鏡像倉庫,它包括權(quán)限管理(RBAC)、LDAP、日志審核、管理界面、自我注冊、鏡像復(fù)制等諸多功能,本文給大家介紹docker compose安裝harbor的方法,需要的朋友參考下吧
    2021-06-06

最新評論

沾化县| 宝鸡市| 庆城县| 城固县| 安塞县| 东阳市| 湄潭县| 房产| 南乐县| 西平县| 宜宾市| 油尖旺区| 岳阳县| 通江县| 伊春市| 额敏县| 兴义市| 香河县| 禄丰县| 新密市| 健康| 扶风县| 舒城县| 青龙| 剑阁县| 安新县| 巴南区| 绍兴市| 东乡| 阳朔县| 壶关县| 墨江| 马山县| 永年县| 大理市| 宜丰县| 于田县| 樟树市| 德阳市| 鱼台县| 灯塔市|