Both docker commit and docker export can export containers as images. What is the difference between them?

While docker commitboth docker exportand can be used to export containers, there are some important differences between them.

  1. docker commit: This command saves the current state of the container as a new image. It saves the container's filesystem changes, process state, etc. to the new image. An image created with docker commita can be used directly as the basis for a new container based on this image. The image contains the filesystem and runtime state of the container.

  2. docker export: This command packs the container's filesystem into a compressed tar file. It does not contain information such as the runtime state, process, and environment variables of the container, but only the file system snapshot of the container. The tar file created by using docker exportcan be imported as a mirror in other Docker environments through docker importthe command. Imported images do not have the same history and metadata as the original container.

Main difference:

  • docker commitThe exported image contains the full filesystem and runtime state of the container and can be used directly as the basis for new containers based on this image.
  • docker exportThe exported tar file contains only a snapshot of the container's filesystem, not the container's runtime state or metadata. It needs to be docker importimported as a mirror before it can be used.

So if you need to preserve the full state of the container and use it as a base to create new containers, you can use that docker commit. If you just want to take a snapshot of the container's file system and import it as an image in other Docker environments, you can use a combination of docker exportand docker import.

おすすめ

転載: blog.csdn.net/a772304419/article/details/132304519