zoukankan      html  css  js  c++  java
  • 第5次系统综合实践

    1、项目结构

    2、构建容器

    Dockfile

    FROM python
    MAINTAINER czh
    WORKDIR /usr/src/app
    COPY requirements.txt ./
    RUN pip install -r requirements.txt -i https://pypi.douban.com/simple  #修改源并安装依赖
    ENTRYPOINT [ "python" ]
    CMD [ "hello.py" ] 

    requirements.txt

    PyMySQL
    cryptography #连接sql
    opencv-python

    建立镜像

    3、程序部署

    1.hello.py:

    print('hello world')
    docker run --rm -v /home/ubuntu/Documents/py/myfile:/usr/src/app py hello.py

    2.date.py:

    # 引入日历模块
    import calendar
     
    # 输入指定年月
    yy = int(input("输入年份: "))
    mm = int(input("输入月份: "))
     
    # 显示日历
    print(calendar.month(yy,mm))
    docker run -it -v /home/ubuntu/Documents/py/myfile:/usr/src/app --rm python:v1 date.py

    3.mysql.py:

    import pymysql
     
    # 打开数据库连接
    db = pymysql.connect("pymysql","root","123456","python" )
     
    # 使用 cursor() 方法创建一个游标对象 cursor
    cursor = db.cursor()
     
    # 使用 execute()  方法执行 SQL 查询 
    cursor.execute("SELECT VERSION()")
     
    # 使用 fetchone() 方法获取单条数据.
    data = cursor.fetchone()
     
    print ("Database version : %s " % data)
     
    # 关闭数据库连接
    db.close()
    docker run --rm -v /home/ubuntu/Documents/py/myfile:/usr/src/app --link=mysql:mysql py mysql.py

    4.opencv.py

    import cv2
    import numpy as np
    
    img = cv2.imread('test.jpg',0)
    ret,thresh = cv2.threshold(img,127,255,0)
    contours,hierarchy = cv2.findContours(thresh, 1, 2)
    
    cnt = contours[0]
    M = cv2.moments(cnt)
    print (M)
     docker run -it --rm -v /home/ubuntu/Documents/py/myfile:/usr/src/app py opencv.py

    4、总结

    总共花费了大概3个小时,实验内容比上次较少

     
  • 相关阅读:
    exp迁移测试库10.2.0.5
    DG_Check检测
    DG Switch over
    CPU查询
    记录数据库中,段大小的数据增长情况
    C++ 多态
    java反射
    git的基本概念
    实现MySQL的Replication
    网页只允许中国用户访问
  • 原文地址:https://www.cnblogs.com/xxylac/p/12938430.html
Copyright © 2011-2022 走看看