赞
踩
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose -v
- version: '3'
- services:
- mysql_text:
- image: mysql:5.7
- ports:
- - 8765:3306
- # 环境变量
- environment:
- WORDPRESS_DB_PASSWORD: foobared
- volumes:
- - /opt/mysql-data:/var/lib/mysql
- redis:
- image: redis
-
- web:
- build:
- context: .
- dockerfile: Dockerfile
- ports:
- - 8088:8000
- # 环境变量
- environment:
- REDIS_HOST: redis
- volumes:
- - /home/djangp_text:/home/djangp_text
-
-
- # 上面的文件拉取的容器,相当于下面这三句被执行
- docker run -id --name=mysql_text -v /opt/mysql-data:/var/lib/mysql -p 8765:3306 -e MYSQL_ROOT_PASSWORD=foobared mysql:5.7
-
- docker run -id --name=redis redis
-
- docker run -id --name=django -v /home/djangp_text:/home/djangp_text -p 8888:8000 -e REDIS_HOST:redis django_t1
- # 启动的时候,可以-e指定给容器环境变量,
- 内部通过,os.environ.get('password', '127.0.0.1') 获取到
-
- docker run -id --name=my_python -e password=xxx -e name=aaaa python:3.6
- # 部署flask redis
- 1 创建Dockerfile
- vim Dockerfile
-
- FROM python:3.6
- COPY . /app
- WORKDIR /app
- RUN pip install flask redis
- EXPOSE 5000
- CMD [ "python", "app.py" ]
-
- 2 创建docker-compose文件
- vim docker-compose.yml
- version: "3"
- services:
- redis:
- image: redis
- web:
- build:
- context: .
- dockerfile: Dockerfile
- ports:
- - 8080:5000
- environment:
- REDIS_HOST: redis
- 3 创建app.py
- vim app.py
- from flask import Flask
- from redis import Redis
- import os
- import socket
- app = Flask(__name__)
- redis = Redis(host=os.environ.get('REDIS_HOST', '127.0.0.1'), port=6379)
- @app.route('/')
- def hello():
- redis.incr('hits')
- return '你好! 查看 %s 次, hostname 是 %s.\n' % (redis.get('hits'),socket.gethostname())
- if __name__ == "__main__":
- app.run(host="0.0.0.0", port=5000, debug=True)
- 4 启动--运行
- docker-compose up
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。