1. 程式人生 > >docker搭建python環境並打包映象(快捷但不規範操作)

docker搭建python環境並打包映象(快捷但不規範操作)

sudo docker pull ubuntu

進入ubuntu容器互動系統:
-t 是啟動終端
-i是允許進行互動
這時候敲python命令會發現沒有python

sudo  docker run -i -t ubuntu /bin/bash

因為純淨的Ubuntu下沒有Python環境,所以需要安裝Python
ubuntu下安裝python(和一般安裝步驟一樣):


sudo apt-get update
sudo apt-get install python2.7

然後在容器內新建一個Python測試Python2.7能否正常執行,發現能夠正常執行

然後退出容器:
exit(直接退出並關閉容器)
Ctrl+Q+P(退出容器,但不關閉容器)

打包裝了python的容器:
命令:docker commit <容器id或容器名> 新的映象名

docker commit ubuntu_python image_test

然後檢視docker的本地映象會發現多了一個image_test映象
在直接執行image_test映象,生成的容器,會發現該容器已經安裝好了Python環境

匯出映象:
-o引數,輸出檔案
需要匯出路徑和檔名
需要匯出的映象名

docker save -o /image/python_image.tar image_test

然後可以將該檔案傳輸到別的安裝了docker的機器,匯入
import 檔案路徑 映象名

docker import /usr/python_image.tar python_ubuntu