python开发案例集锦
Docker compose
[root@iz2ze7pyqb098vwyxxnq3wz /]# docker-compose --version
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)
[root@iz2ze7pyqb098vwyxxnq3wz home]# mkdir compose1
[root@iz2ze7pyqb098vwyxxnq3wz home]# cd compose1/
[root@iz2ze7pyqb098vwyxxnq3wz compose1]# ls
[root@iz2ze7pyqb098vwyxxnq3wz compose1]# vim app.py
[root@iz2ze7pyqb098vwyxxnq3wz compose1]# ls
app.py
[root@iz2ze7pyqb098vwyxxnq3wz compose1]# vim app.py
[root@iz2ze7pyqb098vwyxxnq3wz compose1]# vim Dockerfile
[root@iz2ze7pyqb098vwyxxnq3wz compose1]# vim docker-compose.yml
[root@iz2ze7pyqb098vwyxxnq3wz compose1]# vim docker-compose.yml
[root@iz2ze7pyqb098vwyxxnq3wz compose1]# docker-compose up
[root@iz2ze7pyqb098vwyxxnq3wz home]# rz
[root@iz2ze7pyqb098vwyxxnq3wz home]# ls
1.txt compose2.zip df3 hupu.zip rabbitmq.tar
admin df1 df4 installDocker.zip setuptools-19.6
compose1 df2 hupu python37 setuptools-19.6.tar.gz
[root@iz2ze7pyqb098vwyxxnq3wz home]# unzip compose2.zip
Archive: compose2.zip
creating: compose2/
inflating: compose2/:
inflating: compose2/Dockerfile
inflating: compose2/app.py
inflating: compose2/docker-compose.yml
[root@iz2ze7pyqb098vwyxxnq3wz home]# diff compose1/app.py compose2/app.py
YAML
nginx
build: ./app = docker build -t 镜像 ./app
pip freeze > requirements.txt
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro 只读
privileged: true 给容器root权限