Python Flask镜像如何构建,工具和方法是什么
Admin 2022-09-06 群英技术资讯 664 次浏览
这篇文章将为大家详细讲解有关“Python Flask镜像如何构建,工具和方法是什么”的知识,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
FROM python:3.9.5-slim COPY app.py /src/app.py RUN pip install flask WORKDIR /src ENV FLASK_APP=app.py EXPOSE 5000 CMD ["flask", "run", "-h", "0.0.0.0"]
PS E:\images> docker image build -f .\flask_dockerfile -t flask_py . [+] Building 80.3s (9/9) FINISHED => [internal] load build definition from flask_dockerfile 0.0s => => transferring dockerfile: 38B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/python:3.9.5-slim 12.7s => [internal] load build context 0.0s => => transferring context: 152B 0.0s => [1/4] FROM docker.io/library/python:3.9.5-slim@sha256:9828573e6a0b02b6d0ff0bae0716b027aa21cf8e59ac18a76724d2 47.4s => => resolve docker.io/library/python:3.9.5-slim@sha256:9828573e6a0b02b6d0ff0bae0716b027aa21cf8e59ac18a76724d21 0.0s => => sha256:f42d92068b29045b6893da82032ca4fcf96193be5dcbdcfcba948489efa9e832 1.37kB / 1.37kB 0.0s => => sha256:c71955050276b1e3b4be7e29089e4babeb39957981d162a3d422e084601105d3 7.63kB / 7.63kB 0.0s => => sha256:b4d181a07f8025e00e0cb28f1cc14613da2ce26450b80c54aea537fa93cf3bda 27.15MB / 27.15MB 44.7s => => sha256:a1111a8f2ec3f3a8ee44a123047349a70f87d1cfebb9e48b06520d0eed436a71 2.77MB / 2.77MB 9.3s => => sha256:445d04774519ca200f5c48fd028beaafb49ca763dd58767f1ae7e3933306394c 10.93MB / 10.93MB 32.9s => => sha256:9828573e6a0b02b6d0ff0bae0716b027aa21cf8e59ac18a76724d216bab7ef04 1.86kB / 1.86kB 0.0s => => sha256:24f3f85d41f368fc2dcd569b181ef6cd4c2bee419a32853be2f8c8964cee34af 235B / 235B 11.9s => => sha256:d299f7fb612d59c3d87fcb17028a25c02e94722ef6235e60537a12d0e312abfc 2.64MB / 2.64MB 17.4s => => extracting sha256:b4d181a07f8025e00e0cb28f1cc14613da2ce26450b80c54aea537fa93cf3bda 1.3s => => extracting sha256:a1111a8f2ec3f3a8ee44a123047349a70f87d1cfebb9e48b06520d0eed436a71 0.2s => => extracting sha256:445d04774519ca200f5c48fd028beaafb49ca763dd58767f1ae7e3933306394c 0.5s => => extracting sha256:24f3f85d41f368fc2dcd569b181ef6cd4c2bee419a32853be2f8c8964cee34af 0.0s => => extracting sha256:d299f7fb612d59c3d87fcb17028a25c02e94722ef6235e60537a12d0e312abfc 0.2s => [2/4] COPY app.py /src/app.py 0.1s => [3/4] RUN pip install flask 19.8s => [4/4] WORKDIR /src 0.0s => exporting to image 0.2s => => exporting layers 0.2s => => writing image sha256:0567a371be3f084fb413092b480735083c224023f8801fc723e228a021ea54b1 0.0s => => naming to docker.io/library/flask_py PS E:\images> docker images REPOSITORY TAG IMAGE ID CREATED SIZE flask_py latest 0567a371be3f 10 minutes ago 125MB PS E:\images> docker container run -d -p 5000:5000 0567a371be3f ceb69c7ce778ebcf48a0ad91eb16902814cb20470ddb16d0ba795baa18cf4b01
访问浏览器本地ip:http://127.0.0.1:5000/ 显示Hello, World!
查看容器日志:
PS E:\images> docker logs ceb69c7ce778 * Serving Flask app 'app.py' (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: off * Running on all addresses. WARNING: This is a development server. Do not use it in a production deployment. * Running on http://172.17.0.2:5000/ (Press CTRL+C to quit) PS E:\images> docker logs ceb69c7ce778 * Serving Flask app 'app.py' (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: off * Running on all addresses. WARNING: This is a development server. Do not use it in a production deployment. * Running on http://172.17.0.2:5000/ (Press CTRL+C to quit) 172.17.0.1 - - [13/Jan/2022 08:50:31] "GET / HTTP/1.1" 200 - 172.17.0.1 - - [13/Jan/2022 08:50:31] "GET /favicon.ico HTTP/1.1" 404 -
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
命名空间是从名称到对象的映射,大部分的命名空间都是通过 Python 字典来实现的。命名空间提供了在项目中避免名字冲突的一种方法。各个命名空间是独立的,没有任何关系的,所以一个命名空间中不能有重名,但不同的命名空间是可以重名而没有任何影响。
要想在Flask中处理好异常,有一套自己的异常处理机制,首先,我们必须先知道Flask自己是如何处理异常的。去flask的源码里找一找会发现,在flask源码的app.py文件下,有很多会抛出异常的方法,其中拿一个举例:
这篇文章主要介绍了关于python中逆序的三位数,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
目录1 筛选出数据的指定几行数据2 筛选出数据某列为某值的所有数据记录3 模式匹配4 范围区间值筛选5 获取某一行某一列的某个值6 获取原始的numpy二维数组7 根据条件得到某
这篇文章主要介绍怎么使用Python求解斐波那契第n项,方法多样,逻辑清晰,代码简单详细,有这方面需要的朋友可以参考下
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008