ubuntu下安装docker 打包 python images

ubuntu下安装python

apt-get update
apt-get install python3
apt-get install python3-pip
apt-get install python3-dev
apt-get install openssl
apt-get install libssl-dev
apt-get install libffi-dev

查看是否成功

docker run  -v /user/text/pythonimage:/pythonimage  -w /pythonimage ubuntu python3 test.py

-v参数,冒号前为宿主机目录,必须为绝对路径,冒号后为镜像内挂载的路径
-w参数,是指定为当前镜像工作目录
在本机/user/text/pythonimage下创建一个test.py,执行

打包装python的容器:
命令:docker commit <容器id> 新的镜像名

docker commit 1604777a778c docker/python3test

批量安装库:
命令:docker -v 宿主机目录:容器目录 -w 容器当前工作目录 镜像名 命令

docker run -v /user/text/pythonimage:/pythonimage -w /pythonimage ubuntu pip3 install -r requirements.txt

-v参数,冒号前为宿主机目录,必须为绝对路径,冒号后为镜像内挂载的路径
-w参数,是指定为当前镜像工作目录

因为再启动镜像会到初始化的样子所以再打包一次容器,保留内容

docker commit 62d4eefe7e62 python3test

进入容器:

docker run -i -t -v /user/text/pythonimage:/pythonimage -w /pythonimage python3test /bin/bash

新建一个test.py再执行:
docker run -v /user/text/pythonimage:/pythonimage -w /pythonimage python3test python test.py

导出镜像命令:

docker save -o /user/text/pythonimage/python3test.tar python3test

-o参数,输出文件
需要导出路径喝文件名
需要导出的镜像名

运行:

docker run -p 5000:5000 -v /user/text/pythonimage:/pythonimage  -w /pythonimage python3test python test.py

参考:

https://blog.csdn.net/sherry_rui/article/details/50417215
https://blog.csdn.net/u010900754/article/details/74592184
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值