docker-compose编配Redis,Flask

1.curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-(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)