美文网首页
docker compose 笔记8

docker compose 笔记8

作者: 光小月 | 来源:发表于2019-07-17 16:31 被阅读0次

安装docker-compose

curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` > usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose


pip install -U docker-compose


卸载

rm /usr/local/bin/docker-compose
pip uninstall docker-compose

使用例子

app.py

from flask import Flask
from redis import Redis

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

@app.route('/')
def hello():
     count = redis.incr('hits')
     return 'Hello World! 该页面已被访问 {} 次。\n'.format(count)

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

Dockerfile

FROM python:3.6-alpine
ADD . /code
WORKDIR /code
RUN pip install redis flask
CMD ["python", "app.py"]

docker-compose.yml

version: '3'
services:
  web:
    build: .
    ports:
      - "5000:5000"
   redis:
       image: "redis:alpine"

运行 compose 项目

docker-compose up

结果

[root@localhost local]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
ab9096231b6c        redis:alpine        "docker-entrypoint.s…"   23 minutes ago      Up 23 minutes       6379/tcp                 myweb_redis_1
e84b70f89b32        myweb_web           "python app.py"          23 minutes ago      Up 23 minutes       0.0.0.0:5000->5000/tcp   myweb_web_1

``

相关文章

网友评论

      本文标题:docker compose 笔记8

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