While docker commit
both docker export
and can be used to export containers, there are some important differences between them.
-
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 withdocker commit
a 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. -
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 usingdocker export
can be imported as a mirror in other Docker environments throughdocker import
the command. Imported images do not have the same history and metadata as the original container.
Main difference:
docker commit
The 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 export
The exported tar file contains only a snapshot of the container's filesystem, not the container's runtime state or metadata. It needs to bedocker import
imported 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 export
and docker import
.