标签:debug mes format turn host count style oca code
1.docker compose 安装
curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
2.docker compose demo 使用
1.创建一个目录
mkdir composetest
2.在这个目录创建 app.py 文件
import time import redis from flask import Flask app = Flask(__name__) cache = redis.Redis(host=‘redis‘, port=6379) @app.route(‘/‘) def index(): count = cache.get(‘hits‘) return ‘You are get: {} times.\n‘.format(count) @app.route(‘/incr‘) def incr(): count = cache.incr(‘hits‘) return ‘You are incr: {} times.\n‘.format(count) @app.route(‘/decr‘) def decr(): count = cache.decr(‘hits‘) return ‘You are decr: {} times.\n‘.format(count) if __name__ == "__main__": app.run(host="0.0.0.0", debug=True)
3.创建requirements.txt 文件
文件内容如下:
flask
redis
4.创建一个Dockerfile。
FROM python:3.4-alpine ADD . /code WORKDIR /code RUN pip install -r requirements.txt CMD ["python", "app.py"]
5.创建 docker-compose.yml 文件。
version: ‘3‘ services: web: build: . ports: - "5000:5000" redis: image: "redis:alpine"
6.使用compose构建应用程序
docker-compose up -d
标签:debug mes format turn host count style oca code
原文地址:https://www.cnblogs.com/yg_zhang/p/9744533.html