<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ![關注抖音創業](https://img.kancloud.cn/c5/ce/c5ced2ea291122851697114ca415ff95_1125x1680.png) [TOC] # 案例 > 通過redis記錄點擊數,官網: https://docs.docker.com/compose/gettingstarted/ (1)創建文件夾 ``` mkdir composetest cd composetest ``` (2)創建業務腳本 vi 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) ``` (3)在同目錄下創建 requirements.txt寫入以下內容 ``` flask redis ``` (4)創建 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) 編寫 `docker-compose.yml` ``` version: '3' services: web: build: . ports: - "5000:5000" networks: - app-net redis: image: "redis:alpine" networks: - app-net networks: app-net: driver: bridge ``` (6)通過docker-compose創建容器 `docker-compose up -d` 過程 ``` Creating network "composetest_app-net" with driver "bridge" Building web Step 1/9 : FROM python:3.7-alpine 3.7-alpine: Pulling from library/python c9b1b535fdd9: Pull complete 2cc5ad85d9ab: Pull complete 53a2fca3c2ea: Pull complete 30fce49de8b1: Pull complete ca406aaf66e0: Pull complete Digest: sha256:4e91ff3eed8bdd013178b6d8e55f656b394aeea42945f04389e4af5462e7cb6d Status: Downloaded newer image for python:3.7-alpine ---> a5d195bb2a63 Step 2/9 : WORKDIR /code ---> Running in ea0ca57eacba Removing intermediate container ea0ca57eacba ---> 67903e86148c Step 3/9 : ENV FLASK_APP app.py ---> Running in 0a5a9b5c7b29 Removing intermediate container 0a5a9b5c7b29 ---> 51279a538141 Step 4/9 : ENV FLASK_RUN_HOST 0.0.0.0 ---> Running in 4859db968894 Removing intermediate container 4859db968894 ---> 54e7d97587df Step 5/9 : RUN apk add --no-cache gcc musl-dev linux-headers ---> Running in 99d13fe00994 fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz (1/12) Installing libgcc (9.2.0-r3) (2/12) Installing libstdc++ (9.2.0-r3) (3/12) Installing binutils (2.33.1-r0) (4/12) Installing gmp (6.1.2-r1) (5/12) Installing isl (0.18-r0) (6/12) Installing libgomp (9.2.0-r3) (7/12) Installing libatomic (9.2.0-r3) (8/12) Installing mpfr4 (4.0.2-r1) (9/12) Installing mpc1 (1.1.0-r1) (10/12) Installing gcc (9.2.0-r3) ... ``` (7)訪問 `curl 192.168.136.200:5000` (8)docker-compolse.yml 詳解 > (1)version: '3' ``` 表示docker-compose的版本 ``` > (2)services ``` 一個service表示一個container ``` > (3)networks ``` 相當于docker network create app-net ``` > (4)volumes ``` 相當于-v v1:/var/lib/mysql ``` > (5)image ``` 表示使用哪個鏡像,本地build則用build,遠端則用image ``` > (6)ports ``` 相當于-p 8080:8080 ``` > (7)environment ``` 相當于-e ``` # scale擴縮容 ## docker-compolse.yml文件中的ports去掉 ``` version: '3' services: web: build: . networks: - app-net redis: image: "redis:alpine" networks: - app-net networks: app-net: driver: bridge ``` ## 創建service `docker-compose up -d . ` ## 對python容器進行擴縮容 ``` docker-compose up --scale web=3 -d ``` > 檢查 ``` docker-compose ps docker-compose logs web ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看