flask dockerfile,python docker镜像
这篇文章主要介绍了构建构建一个PythonFlask镜像,对正在学习的你有一定的参考价值,需要的小伙伴可以参考一下
目录
1.大蟒程序2.Dockerfile3开始构建一个小的演示
1.Python 程序
从烧瓶进口烧瓶
app=Flask(__name__)
@app.route(/)
def hello_world():
回复"你好,世界!"
2.Dockerfile
来自python:3.9.5-slim
复制app.py /src/app.py
运行点安装烧瓶
工作主管/服务代表
ENV FLASK_APP=app.py
暴露5000
CMD [烧瓶,运行,-h , 0.0.0.0]
3.开始构建一个小的demo
PS e : images docker image build-f,flask_dockerfile -t flask_py .
[ ]建造80.3秒(9月9日)完成
=[内部]从flask_dockerfile 0.0s加载生成定义
==传输: 38B 0.0s
=[内部]负载dockerignore 0.0s
==传输上下文: 2B 0.0s
=[内部]加载docker.io/library/python:3.9.5-slim 12.7版本的元数据
=[内部]加载生成上下文0.0s
==传输上下文: 152B
=[1/4]来自docker。io/库/python :3。9 .5-slim @ sha 256:9828573 e 6 a 0 b 02 b 6d 0 ff 0 BAE 0716 b 027 aa 21 cf 8 e 59 AC 18 a 76724d 2 47.4s
==解析docker。io/库/python :3。9 .5-slim @ sha 256:9828573 e 6 a 0 b 02 b 6d 0 ff 0 BAE 0716 b 027 aa 21 cf 8 e 59 AC 18 a 76724d 21 0.0s
==sha 256: f42d 92068 b 29045 b 6893 da 82032 ca 4 fcf 96193 be 5 dcbdcfcba 948489 EFA 9 e 832 1.37 kb/1.37 kb 0.0s
==sha 256: c 71955050276 B1 E3 B4 be 7 e 29089 E4 babeb 39957981d 162 a 3d 422 e 084601105d 3 7.63 kb/7.63 kb 0.0s
==
gt; 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
到此这篇关于Dockerfile构建一个Python Flask 镜像的文章就介绍到这了,更多相关Dockerfile构建一个Python Flask 镜像内容请搜索盛行IT软件开发工作室以前的文章或继续浏览下面的相关文章希望大家以后多多支持盛行IT软件开发工作室!
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。