Compose 入门
准备
步骤 1:Setup
$ mkdir composetest
$ cd composetestimport time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)步骤 2:创建一个 Dockerfile
步骤 3:在 Compose 文件中定义服务
Web 服务
Redis 服务
步骤 4:通过 Compose 构建和运行你的 app
步骤 5:编辑你的 Compose 文件并加入 mount 映射
步骤 6:使用 Compose 重新构建和运行应用
步骤 7:更新应用
步骤 8:试用其他命令
最后更新于