ubuntu下安裝docker 打包 python images
阿新 • • 發佈:2018-12-15
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