启动镜像:
$ docker run --env-file=.flaskenv myapp myapi init $ docker run --env-file=.flaskenv -p 5000:5000 myapp myapi run -h 0.0.0.0 * Serving Flask app "myapi.app:create_app" (lazy loading) * Environment: development * Debug mode: on * Running on :5000/ (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger PIN: 214-619-010使用docker-compose启动:
$ docker-compose up -d $ docker ps $ docker exec -it <container_id> myapi init使用docker-compose 和 Makefile启动
make init Makefile 命令 make init # 初始化环境 make build # 构建镜像 make run # 启动镜像 make db-migrate # 迁移数据 make db-upgrade # 数据映射到数据库 make test # 执行测试 使用Swagger打开UI页面地址::5000/swagger-ui
页面如下:
在config.py文件进行配置:
APISPEC_TITLE: 页面标题,默认: {{cookiecutter.project_name}}
APISPEC_VERSION: api版本,默认: 1.0.0
OPENAPI_VERSION: OpenAPI 版本,默认: 3.0.2
SWAGGER_JSON_URL: JSON规范校验地址, 默认: /swagger.json
SWAGGER_UI_URL: 页面UI地址,默认: /swagger-ui
SWAGGER_URL_PREFIX: 蓝图URL前缀, 默认: None
Enjoy your code, good luck.