iT邦幫忙

2022 iThome 鐵人賽

DAY 23
0

docker檔案要有的結構:

app.py:

import os

from flask import Flask
from flask_redis import FlaskRedis


app = Flask(__name__)
app.config['REDIS_URL'] = os.environ['REDIS_URL']

r = FlaskRedis(app)


@app.route('/')
def index():
    if not r.exists("count"):
        r.set("count", 0)
    r.incr("count")
    return r.get("count")


if __name__ == "__main__":
    app.run(host="0.0.0.0")

docker-compose.yml:

version: '3.8'

services:
  backend:
    build: .
    container_name: backend_flask
    networks:
      - net
    ports:
      - 5000:5000
    environment:
      - REDIS_URL=redis://cache:6379/0
    volumes:
      - .:/project:ro
    command: "python3 app.py"
  cache:
    image: redis
    container_name: database_redis
    networks:
      - net
    ports:
      - 6379:6379

networks:
  net:
    name: frnet
    driver: bridge

Dockerfile:

FROM python:3.9.10-alpine3.15

WORKDIR /test-project

COPY * .

RUN pip install -r requirements.txt

EXPOSE 5000

CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app", "--preload"]

以及產生一個requirements檔


上一篇
<DAY22><玩玩AI繪圖>NOVEL AI
下一篇
<DAY24>
系列文
九局下半的學習日誌30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言