导出镜像
docker save -o xxx.tar image1 image2 ….imagen
解压tar包之后,有下面一些文件
manifest
type manifestItem struct {
Config string
RepoTags []string
Layers []string
Parent image.ID `json:",omitempty"`
LayerSources map[layer.DiffID]distribution.Descriptor `json:",omitempty"`
}
config是镜像的config文件
RepoTags一般都是null
Layres是各个层的目录
config文件的格式
// V1Image stores the V1 image configuration.
type V1Image struct {
// ID is a unique 64 character identifier of the image
ID string `json:"id,omitempty"`
// Parent is the ID of the parent image
Parent string `json:"parent,omitempty"`
// Comment is the commit message that was set when committing the image
Comment string `json:"comment,omitempty"`
// Created is the timestamp at which the image was created
Created time.Time `json:"created"`
// Container is the id of the container used to commit
Container string `json:"container,omitempty"`
// ContainerConfig is the configuration of the container that is committed into the image
ContainerConfig container.Config `json:"container_config,omitempty"`
// DockerVersion specifies the version of Docker that was used to build the image
DockerVersion string `json:"docker_version,omitempty"`
// Author is the name of the author that was specified when committing the image
Author string `json:"author,omitempty"`
// Config is the configuration of the container received from the client
Config *container.Config `json:"config,omitempty"`
// Architecture is the hardware that the image is built and runs on
Architecture string `json:"architecture,omitempty"`
// OS is the operating system used to build and run the image
OS string `json:"os,omitempty"`
// Size is the total size of the image including all layers it is composed of
Size int64 `json:",omitempty"`
}
// Image stores the image configuration
type Image struct {
V1Image
Parent ID `json:"parent,omitempty"`
RootFS *RootFS `json:"rootfs,omitempty"`
History []History `json:"history,omitempty"`
OSVersion string `json:"os.version,omitempty"`
OSFeatures []string `json:"os.features,omitempty"`
// rawJSON caches the immutable JSON associated with this image.
rawJSON []byte
// computedID is the ID computed from the hash of the image config.
// Not to be confused with the legacy V1 ID in V1Image.
computedID ID
}
Layer层json文件格式
layer层中有json和VERSION两个文件
json文件的格式就是V1Image
docker save流程
Save(names []string, outStream io.Writer)
func (s *saveSession) save(outStream io.Writer) error {
for id, imageDescr := range s.images {
foreignSrcs, err := s.saveImage(id)
}
...生成manifest文件
fs, err := archive.Tar(tempDir, archive.Uncompressed)
}
func (s *saveSession) saveImage(id image.ID) (map[layer.DiffID]distribution.Descriptor, error) {
for i := range img.RootFS.DiffIDs {
v1ID, err := v1.CreateID(v1Img, rootFS.ChainID(), parent)
v1Img.ID = v1ID.Hex()
src, err := s.saveLayer(rootFS.ChainID(), v1Img, img.Created)
}
configFile := filepath.Join(s.outDir, id.Digest().Hex()+".json")
if err := ioutil.WriteFile(configFile, img.RawJSON(), 0644); err != nil {
return nil, err
}
}
func (s *saveSession) saveLayer(id layer.ChainID, legacyImg image.V1Image, createdTime time.Time) (distribution.Descriptor, error) {
首先save列表参数中所有的image,然后生成manifest文件
每个image保存的过程是:
保存每一个层,每个层中有一个v1Img结构
生成config json文件