Docker运行中的容器,重新打包成镜像和压缩以及解压和载入镜像

本文主要讲如何将docker运行中的容器,重新打包成镜像和压缩以及解压和载入镜像。

1. 将容器保存成镜像

1
sudo docker commit 85a2fe8491fb test/postgis:11.0-2.5

2. 将镜像打包

1
docker save -o testpostgis.tar test/postgis:11.0-2.5

3. 将镜像包压缩

1
2
3
sudo tar -zcvf testpostgis.tar.gz testpostgis.tar
# 还有一种容器的打包和压缩一步到位的方法: 
docker save test/postgis:11.0-2.5 | gzip > testpostgis.tar.gz

4. docker镜像压缩包解压及镜像载入

1
2
3
4
5
6
7
8
# 压缩包解压 得到.tar格式的镜像包
tar -zxvf testpostgis.tar.gz 
# 镜像载入
sudo docker load -i testpostgis.tar
# .gz 镜像包载入
sudo docker load -i testpostgis.tar.gz 
# 查看镜像
sudo docker images
0%