美文网首页
docker-compose编配Redis,Flask

docker-compose编配Redis,Flask

作者: liser0205 | 来源:发表于2019-05-06 10:24 被阅读0次

1.curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-(uname -s)-(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
2.mkdir composeapp
touch Dockerfile touch app.py touch requirements.txt touch docker-compose.yml docker pull python
vi app.py

from flask import Flask
from redis import Redis
import os

app=Flask(__name__)
redis=Redis(host="redis",port=6379)

@app.route('/')
def hello():
    redis.incr('hits')
    return 'Hello Docker Book reader!I have been seen {0} times'.format(redis.get('hits'))

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

vi Dockerfile

FROM python:latest
ADD . /composeapp
WORKDIR /composeapp
RUN pip install -r requirements.txt

vi requirements.txt

flask
redis

vi docker-compose.yml

version: '2'
services:
 web:
  build: .
  command: python app.py
  ports:
   - "5000:5000"
  volumes:
   - .:/code
  depends_on:
   - redis
 redis:
  image: redis

docker-compose up

相关文章

网友评论

      本文标题:docker-compose编配Redis,Flask

      本文链接:https://www.haomeiwen.com/subject/sraloqtx.html