docker-compose small demo

docker-compose.yml :

web:

  image: composeapp

  command: python app.py

  ports:

    -  "5000:5000"

  volumes:

    -  .:/composeapp

  links:

    -  redis

redis:

  image: redis


---  app.py:



#!/usr/bin/env python2

# -*- coding: utf-8 -*-

#导入Flask和Redis模块

from flask import Flask

from redis import Redis

import os

#创建Flask app

app = Flask(__name__)

#通过host连接到Redis

redis = Redis(host="redis",port=6379)

#指定访问路径

@app.route('/')

def hi():

    redis.incr("ping")

    return 'hi , you have ping {0} times'.format(redis.get('ping'))

if __name__ == '__main__':

    app.run(host="0.0.0.0",debug=True)



------------------ Dockerfile


#指定基镜像为python2.7

FROM python:2.7

MAINTAINER REGANZM [email protected]

ADD . /composeapp

WORKDIR /composeapp

RUN pip install -r requirements.txt


---------- requirements.txt:


flask

redis

你可能感兴趣的:(docker-compose small demo)