FROM daocloud.io/ubuntu:trusty MAINTAINER water-law <dockerwaterlaw@daocloud.io> RUN apt-get update && \ apt-get install -y python3 \ python3-dev \ python3-pip \ && apt-get clean \ && apt-get autoclean \ && rm -rf /var/lib/apt/lists/* RUN mkdir -p /app WORKDIR /app EXPOSE 80 CMD ["bash"]
建立空文件夾, 將 Dockerfile 文件放在此目錄html
運行 docker build -t [tagname] .python
docker imagesdocker
docker save -o [output_name] [image]ubuntu
其中 output_name 通常是 tar, tar.xz 格式bash
docker run -it -v E:Projectswaterlawblog:/home/code [image] /bin/bashapp
exitide
docker start [OPTIONS] CONTAINER [CONTAINER...]ui
說明: 對容器的修改是永久保存到文件系統的。code
可發現 E:Projectswaterlawblog 是掛載到 docker 容器的 /home/code 目錄的htm
好比 安裝 virtualenv 且在 /home 目錄使用 virtualenv -p python3 pysp
建立虛擬環境, 進入 /home/code, 運行 pip3 install -r requirements.txt
先退出容器 exit
基於舊的 container 提交新的 docker 鏡像
docker commit -m "commit message" -a "author info" [container_id] image_name:tag
示例
docker commit -m "earth" -a "zjp" 846edc550555 kuaiyun:earth
提示: 以上命令會打了一個 REPOSITORY 爲 kuaiyun、 TAG 爲 earth 的鏡像, 可經過
docker images 查看。
docker ps -a
| CONTAINER I D| IMAGE | COMMAND | CREATED STATUS | PORTS | NAMES |
| caa1f263a254 | myubuntu-base | "/bin/bash" | 32 minutes ago Exited (0) 54 seconds ago | | relaxed_lumiere |
docker export -o [outputfile] [container_id]
docker import [container_file] [command]
我這裏 command 是 /bin/bash, 因此 docker import [container_file] bash
docker load < [tar file]
注意 save 和 load 是配對的, import 和 export 是配對的。 import 還要加上 command。