Files
Kubernetes/Docker/Docs/Docker使用文档/Docker镜像打包.md
offends b44594def6
All checks were successful
continuous-integration/drone Build is passing
修改和新增
2025-12-23 01:53:01 +08:00

764 B

本文作者:丁辉

Docker镜像打包

默认打包

  1. 打包

    docker save -o image.tar nginx:latest
    
  2. 导入

    docker load -i image.tar
    

打包并压缩

  1. 打包并压缩

    docker save nginx:latest | gzip -c > image.tar.gz
    
  2. 解压并导入

    gunzip -c image.tar.gz | docker load
    

批量打包

  • 第一种

    docker save $(docker images | grep -v REPOSITORY | awk 'BEGIN{OFS=":";ORS=" "}{print $1,$2}') -o k8s-master.tar
    
  • 第二种

    将需要统一打包的镜像写在文件内

    cat > images.txt <<EOF
    nginx:alpine
    nginx:latest
    EOF
    

    打包

    docker save -o images.tar.gz $(cat images.txt)