mirror of
https://github.com/wsargent/docker-cheat-sheet.git
synced 2025-09-21 21:30:48 +02:00
Added load save import export
Example of load/save image and import/export container. Briefly explained the difference between them
This commit is contained in:
parent
cc430d3442
commit
ef3e25fa69
1 changed files with 33 additions and 0 deletions
|
@ -13,6 +13,7 @@
|
|||
* [仓管中心和仓库(Registry & Repository)](#仓管中心和仓库registry--repository)
|
||||
* [Dockerfile](#dockerfile)
|
||||
* [层(Layers)](#层layers)
|
||||
* [加载/保存(Load/Save) 导入/导出(Import/Export)](#load-save-import-export)
|
||||
* [链接(Links)](#链接links)
|
||||
* [卷标(Volumes)](#卷标volumes)
|
||||
* [暴露端口(Exposing Ports)](#暴露端口exposing-ports)
|
||||
|
@ -332,6 +333,38 @@ docker run -v /Users/wsargent/myapp/src:/src
|
|||
|
||||
可还可以考虑运行一个纯数据容器,像[这里](http://container42.com/2013/12/16/persistent-volumes-with-docker-container-as-volume-pattern/)所说的那样,提供可移植数据。
|
||||
|
||||
## 加载/保存(Load/Save) 导入/导出(Import/Export)
|
||||
|
||||
Docker 允许你加载/保存镜像以及导入/导出容器。
|
||||
|
||||
### 加载/保存镜像
|
||||
|
||||
从文件中加载镜像:
|
||||
```
|
||||
docker load < my_image.tar.gz
|
||||
```
|
||||
保存既有镜像:
|
||||
```
|
||||
docker save my_image:my_tag > my_image.tar.gz
|
||||
```
|
||||
|
||||
### 导入/导出容器
|
||||
|
||||
从文件中将容器作为镜像导入:
|
||||
```
|
||||
cat my_container.tar.gz | docker import - my_image:my_tag
|
||||
```
|
||||
|
||||
导出既有容器:
|
||||
```
|
||||
docker export my_container > my_container.tar.gz
|
||||
```
|
||||
|
||||
### 加载被保存的镜像和导入作为镜像导出的容器之间的不同
|
||||
|
||||
通过 `load` 命令来加载镜像,会创建一个新的镜像,并继承原镜像的所有历史。
|
||||
通过 `import` 将容器作为镜像导入,也会创建一个新的镜像,但并不包含原镜像的历史,因此生成的镜像会比使用加载方式生成的镜像要小。
|
||||
|
||||
## 暴露端口(Exposing ports)
|
||||
|
||||
通过宿主容器暴露输入端口是相当[繁琐,但有效](https://docs.docker.com/reference/run/#expose-incoming-ports)的。
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue