美文网首页k8s/istio
python执行文件打Docker镜像

python执行文件打Docker镜像

作者: 国服最坑开发 | 来源:发表于2021-08-14 16:49 被阅读0次

    0x01 导出python依赖

    在 app.py 当前目录下执行名令, 得到依赖文件

     pip3 freeze > requirements.txt
    

    但不是所有依赖都是必需的, 可以根据app.py 的头部依赖删除不需要的部分

    此时, 当前目录存在两个文件

    • app.py
    • requirements.txt

    0x02 Dockerfile 编写

    关键点是 基础镜像的选择, 然后在Dockerfile中执行pip install 动作, 完成依赖拉取

    FROM python:3.8-slim-buster
    COPY ./requirements.txt /
    COPY ./app.py  /
    
    RUN pip install -r /requirements.txt
    
    EXPOSE 80
    
    CMD ["python", "/app.py"]
    

    0x03 打镜像, 自测

    docker build .
    docker run -p 10080:80  {imageId} 
    

    相关文章

      网友评论

        本文标题:python执行文件打Docker镜像

        本文链接:https://www.haomeiwen.com/subject/lkdebltx.html