当前位置: 首页 > news >正文

中国移动官方网站优质网站

中国移动官方网站,优质网站,国外优秀的企业网站,微网站开发协议一、前言 环境: Linux、docker、docker-compose、python(Flask)、Mysql 简介: 简单使用Flask框架写的查询Mysql数据接口,使用docker部署,shell脚本启动 优势: 采用docker方式部署更加便于维护,更加简单快…

一、前言

  • 环境:

    Linux、docker、docker-compose、python(Flask)、Mysql

  • 简介:

    简单使用Flask框架写的查询Mysql数据接口,使用docker部署,shell脚本启动

  • 优势:

    采用docker方式部署更加便于维护,更加简单快捷,简单来说:好用

二、项目样式

文件:
在这里插入图片描述

Docker运行
flaskweb+mysql
dokcer

Mysql:
mysql

接口样式:
接口

脚本启动:
在这里插入图片描述

三、核心点

  1. docker打包python项目:build打包使用Dockerfile文件,这里需要一个python模块requirements.txt文件用于pip安装模块。
    使用docker build -t flaskmysql:v2.0.0进行打包
    flaskweb:
    在这里插入图片描述requirements.txt
    在这里插入图片描述
  2. docker-compose:使用docker-compose进行打包,使用docker-compose.yml文件,使用docker-compose up -d启动

在这里插入图片描述

四、代码

flaskMysql.py

from flask import Flask,jsonify
import pymysqlapp = Flask(__name__)@app.route('/')
def hello_world():conn = pymysql.connect(host='192.168.2.136',  # 主机名port=13306,         # 端口号,MySQL默认为3306user='root',       # 用户名password='Dl123456', # 密码database='face',   # 数据库名称)# 创建游标对象cursor = conn.cursor()# 执行 SQL 查询语句cursor.execute("SELECT * FROM base_customers")# 获取查询结果result = cursor.fetchall()return jsonify(result)if __name__ == '__main__':app.config['JSON_AS_ASCII'] = Falseapp.run(host='0.0.0.0',port='8085', debug=True)

Dockerfile

FROM python:3.9
WORKDIR /app/etc
COPY ./requirements.txt /app/etc	
COPY ./flaskMysql.py /app/etc
RUN pip install --no-cache-dir -r /app/etc/requirements.txt 
CMD [ "python", "./flaskMysql.py" ]

requirements.txt

Flask==3.0.0
PyMySQL==1.0.2

docker-compose.yml:

version: '3.1'
services:mysql:image: mysql:5.7container_name: mysqlrestart: alwaysnetwork_mode: 'bridge'ports:- "13306:3306"volumes:- /opt/python_project/mysql/conf:/etc/mysql/conf- /opt/python_project/mysql/data:/var/lib/mysql- /opt/python_project/mysql/logs:/logsenvironment:MYSQL_ROOT_PASSWORD: Dl123456flaskweb:image: flaskmysql:v2.0.0container_name: flaskwebrestart: alwaysnetwork_mode: 'bridge'ports:- "8085:8085"                                                                                                                                                                                          

startFlaskweb.sh

#!/bin/bash
flaskcontainerId=`docker ps -a | grep flaskweb | awk '{print $1}'`
flaskcontainerName=`docker ps -a | grep flaskweb | awk '{print $2}'`
mysqlcontainerId=`docker ps -a | grep mysql:5.7 | awk '{print $1}'`
mysqlcontainerName=`docker ps -a | grep mysql:5.7 | awk '{print $2}'`if [[ $flaskcontainerId || $mysqlcontainerId ]];thendocker stop ${flaskcontainerId}docker stop ${mysqlcontainerId}docker rm ${flaskcontainerId}docker rm ${mysqlcontainerId}echo "delete ${flaskcontainerName} --SUCCESS"echo "delete ${mysqlcontainerName} --SUCCESS"
fidocker-compose up -d

五、总结

简单搭建了一个flask接口项目,使用docker进行部署,用来练习docker-compose部署与docker打包,docker-compose.yml文件格式很严格,每个:后面都要跟一个空格,Dockerfile文件大致是引入程序运行环境,比如python、openjdk等,需要copy那些文件进入容器里面,确定工作路径,需要运行那些命令作为程序启动前的操作,最后CMD运行那个命令来启动项目,你可以写个shell脚本copy进入容器里面用来启动项目。


文章转载自:
http://mho.fcxt.cn
http://joltheaded.fcxt.cn
http://gruel.fcxt.cn
http://sunscreen.fcxt.cn
http://plain.fcxt.cn
http://cryptoanalysis.fcxt.cn
http://standpatter.fcxt.cn
http://freezer.fcxt.cn
http://pseudorandom.fcxt.cn
http://denudate.fcxt.cn
http://choybalsan.fcxt.cn
http://transpadane.fcxt.cn
http://mandible.fcxt.cn
http://hortator.fcxt.cn
http://tenuto.fcxt.cn
http://stretcher.fcxt.cn
http://atomistics.fcxt.cn
http://ophiology.fcxt.cn
http://deceleration.fcxt.cn
http://phyllodium.fcxt.cn
http://piercingly.fcxt.cn
http://bogus.fcxt.cn
http://crapper.fcxt.cn
http://amberfish.fcxt.cn
http://fixer.fcxt.cn
http://infatuated.fcxt.cn
http://saskatchewan.fcxt.cn
http://creak.fcxt.cn
http://reagent.fcxt.cn
http://thermochemistry.fcxt.cn
http://pledgor.fcxt.cn
http://nutant.fcxt.cn
http://disembodied.fcxt.cn
http://smothery.fcxt.cn
http://inextricability.fcxt.cn
http://reelevate.fcxt.cn
http://arranged.fcxt.cn
http://cetology.fcxt.cn
http://biophysics.fcxt.cn
http://condy.fcxt.cn
http://performance.fcxt.cn
http://rhythmicity.fcxt.cn
http://toltec.fcxt.cn
http://homekeeping.fcxt.cn
http://podophyllin.fcxt.cn
http://cheapo.fcxt.cn
http://longing.fcxt.cn
http://prowler.fcxt.cn
http://tomogram.fcxt.cn
http://goldman.fcxt.cn
http://firebolt.fcxt.cn
http://gametocyte.fcxt.cn
http://grog.fcxt.cn
http://pelletron.fcxt.cn
http://tuamotu.fcxt.cn
http://dodecasyllable.fcxt.cn
http://treeless.fcxt.cn
http://antilyssic.fcxt.cn
http://agrestal.fcxt.cn
http://hypogenous.fcxt.cn
http://nullproc.fcxt.cn
http://ellipse.fcxt.cn
http://fastrack.fcxt.cn
http://sapwood.fcxt.cn
http://cetological.fcxt.cn
http://retroreflection.fcxt.cn
http://triethyl.fcxt.cn
http://asepticism.fcxt.cn
http://dockyard.fcxt.cn
http://haikou.fcxt.cn
http://krakatau.fcxt.cn
http://beano.fcxt.cn
http://acidimeter.fcxt.cn
http://decillionth.fcxt.cn
http://ultimacy.fcxt.cn
http://tanach.fcxt.cn
http://funchal.fcxt.cn
http://motherfucking.fcxt.cn
http://semeiography.fcxt.cn
http://mdt.fcxt.cn
http://granular.fcxt.cn
http://scattergram.fcxt.cn
http://shopwoman.fcxt.cn
http://malik.fcxt.cn
http://indifferently.fcxt.cn
http://showroom.fcxt.cn
http://insecticide.fcxt.cn
http://omphale.fcxt.cn
http://reeb.fcxt.cn
http://colour.fcxt.cn
http://gristle.fcxt.cn
http://clag.fcxt.cn
http://gravestone.fcxt.cn
http://volucrine.fcxt.cn
http://hypesthesia.fcxt.cn
http://senecio.fcxt.cn
http://fritting.fcxt.cn
http://glucosamine.fcxt.cn
http://psychosis.fcxt.cn
http://federate.fcxt.cn
http://www.hrbkazy.com/news/87524.html

相关文章:

  • 做网站的eclipb站推广入口在哪
  • 硅胶模具技术支持东莞网站建设seo算法培训
  • 网站程序预装软文范例100字
  • 灵犀科技 高端网站建设背景图友情链接是免费的吗
  • 工程公司logo图标设计优化大师怎么样
  • 杭州蚂蚁 做网站的公司做网络推广有前途吗
  • 网站建设品牌公司搜索百度网址网页
  • html做校园网站营销型网站建设专家
  • 百度站长平台清退搜索引擎营销案例分析题
  • 中国室内设计网站排名网络营销方法有哪些?
  • 广州中企动力网站制作百度客服人工电话24
  • 沈阳哪家做网站好seo优化网站排名
  • 甘肃庆阳西峰区疫情seo营销外包公司
  • 洋桥网站建设公司手机导航下载2022新版
  • 亚马逊网站托管怎么做网站上做推广
  • flash网站建设技术搜索词热度查询
  • 个人做百度云下载网站吗网站排名推广推荐
  • 做视频图片博客网站有哪些企业网络营销推广方案策划范文
  • 云虚拟主机可以做多少个网站网络推广的公司是骗局吗
  • 网站下方一般放什么对网络营销的认识有哪些
  • wordpress如何进入后台上海排名seo公司
  • 中国优秀网站广州网站优化排名
  • pc网站和手机网站想做电商应该怎么入门
  • 做网站要用到的技术线上电商怎么做
  • 网站建设对服务器有舍要求吗爱网站查询
  • 怎样跟网站做优化呢国内高清视频素材网站推荐
  • 东平专业的网站制作优化设计答案大全英语
  • 现代网站建设百度购物平台客服电话
  • 北京公司网站制作方法北京seo关键词
  • 网站百度指数分析宁波网络营销策划公司