Converting docker tar image containers to each other

It's been a while since I learned to use docker, but it's always easy to forget the basics

After sorting out the documents I saw before, I saw a question how to export a container as a tar. I thought it was to save it as an image first and then save it.

After searching for information, I found that this is not the case

I draw a command diagram

Use centos_latest.tar here

tar > images

docker load -i centos_latest.tar   
docker tag pid centos:latest

why load?

Because when the image is save to save the tar package, use load to export it

Why use tags?

Because the image imported by load does not have a name, it needs to be tagged with a tag before it can be used.

images > container

docker run -dit centos:latest /bin/bash   //示例启动代码

Here the container is running docker ps, you can see

container > images

docker commit pid new_centos:latest /bin/bash

There are two ways to generate images: Dockerfile and commit

As for the difference between these two methods, I will write next time.

images> tar

docker save new_centos:latest > new_centos.tar

It must be added, >otherwise it will report an error

container > tar

docker export pid > centos_container.tar

export exports the container directly into a tarball

tar > images

docker import centos_container.tar centos:latest

The difference between docker save and docker export

Summarize the difference between docker save and docker export:

  1. Docker save saves the image, and docker export saves the container;
  2. docker load is used to load the image package, docker import is used to load the container package, but both will be restored to the image;
  3. docker load cannot rename the loaded image, while docker import can specify a new name for the image.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325124887&siteId=291194637