惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
D
Docker
有赞技术团队
有赞技术团队
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
H
Help Net Security
美团技术团队
MyScale Blog
MyScale Blog
B
Blog RSS Feed
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
阮一峰的网络日志
阮一峰的网络日志
A
About on SuperTechFans
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
G
Google Developers Blog
月光博客
月光博客
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs

博客园 - 干炸小黄鱼

timex 处理时间戳 gorm-gen go 雪花算法 golang每日一库--协程池库ants golang每日一库--json解析库gjson python高级编程-asyncio python高级编程-condition python高级编程-event python装饰器-自动重试 EAP系统 go实现实现 SECS/GEM 协议 设备通信协议 SECS go项目使用Jenkins进行CICD go操作ES mongo db聚合查询 go如何使用mongodb Apache ShardingSphere paxos and raft (分布式一致性算法) go使用zookeeper分布式锁以及和redis差异 go使用 seata 示例 Alibaba 分布式事务 Seata go中使用saga go中使用TCC示例 分布式事务TCC 熔断器 Hystrix OR Sentinel k8s下部署consul and etcd Consul OR Etcd 【力扣hot100】双指针-盛水最多的容器 【力扣hot100】滑动窗口-最小覆盖子串 shell脚本合集
简单的python web项目的docker-compose.yml 示例
干炸小黄鱼 · 2024-08-12 · via 博客园 - 干炸小黄鱼

一个简单的 python web项目, 包含redis, mysql, nginx, 定时业务调度等
其中web启动注册了自定义命令 flask create-db && flask init-db && uwsgi /web/uwsgi.ini

version: '3.5'

services:
  db:
    image: mysql
    container_name: yeping_mysql
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: yeping9527
      MYSQL_DATABASE: yeping9527
      LANG: C.UTF-8
    volumes:
      - ./db_data:/var/lib/mysql
      - ./mysql_files:/var/lib/mysql-files
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime:ro
    # ports: 
    #   - "127.0.0.1:3309:3306"
    restart: unless-stopped
    privileged: true
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
  redis:
    image: redis:alpine
    container_name: yeping_redis
    volumes:
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
  web:
    image: yeping_web:v106
    container_name: yeping_web
    command: bash -c "wait-for-it -t 0 db:3306; wait-for-it -t 0 redis:6379; cd /web/主目录 && export FLASK_APP=sites && flask create-db && flask init-db && uwsgi /web/uwsgi.ini"
    volumes:
      - /root/.ssh/:/root/.ssh
      - .:/web
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime:ro
      - ./db_data:/data/db_data
      - ./mysql_files:/data/mysql_files
    depends_on:
      - db
      - redis
    #ports:
    #  - 8112:8000
    restart: unless-stopped
    privileged: true
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
  nginx:
      image: nginx:alpine
      container_name: yeping_nginx
      environment:
        LANG: C.UTF-8
      ports:
        - "443:443"
        - "80:80"
      volumes:
        - /opt/work/yeping/config/nginx:/nginx
        - /opt/work/yeping:/opt/work/yeping
        - /opt/work/yeping/config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
        - /var/log/yeping/nginx/:/var/log/yeping/nginx/
        - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime:ro
      restart: unless-stopped
      privileged: true
      stdin_open: true
      tty: true
      logging:
        driver: "json-file"
        options:
          max-size: "10m"
  schedulers:
    image: yeping:v106
    container_name: yeping_schedulers
    command: sh -c 'cd /web/主目录 && python -u -m sites.scripts.schedulers'
    volumes:
      - .:/web
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime:ro
      - /root/.ssh:/root/.ssh
      - ./db_data:/data/db_data
      - ./mysql_files:/data/mysql_files
    depends_on:
      - web
    restart: unless-stopped
    privileged: true
    logging:
      driver: "json-file"
      options:
        max-size: "10m"

自定义清库和数据库初始化命令

import click
@app.cli.command(help="Create all tables form models")
@click.option("--drop", is_flag=True, help="Create after drop.")
def create_db(drop):
    # 文件锁
    lock_file = "init_create.lock"
    if os.path.exists(lock_file):
        logging.warning("不是第一次启动,无需创建表。。。")
        return
    if drop:
        db.drop_all()
    db.create_all()
    os.mknod(lock_file)

@app.cli.command(help="Initialization app data")
def init_db():
    # 数据库初始化操作