Docker commit vs export

What is the difference between docker export and commit and when to use ?

Please check here:
https://docs.docker.com/engine/reference/commandline/export/

https://docs.docker.com/engine/reference/commandline/commit/

Thanks,
Trung Tran.

docker export and docker commit are both used in Docker to create new images, but they have different functionalities.

docker export allows you to export the contents of a container as a tarball file. This means that you can save the state of the container at a particular point in time and share it with others. However, you can’t use the exported file to recreater its image.

On the other hand, docker commit allows you to create a new image from an existing container. This means that you can modify the container and then save it as a new image. You can then use this image to recreate the container or create new containers based on it.

1 Like

The docker export and docker commit commands serve different purposes in Docker:

docker export: This command allows you to export the contents of a container as a tar archive. It captures the current state of the container filesystem, including files, directories, and metadata. The exported tar archive does not include the container’s underlying image layers or the information needed to reproduce the container in the same state. The primary use case for docker export is to extract files or data from a container, rather than preserving the container’s state or creating a new image.

docker commit: This command creates a new image from the changes made to a container. It takes a container and its filesystem, along with any modifications, and saves it as a new image. The resulting image includes all the layers from the original image, as well as any new or modified layers introduced during the container’s runtime. The docker commit command is useful when you want to create a new image based on the changes made within a container, allowing you to capture the container’s state and configurations as a new image that can be shared or used to create new containers.

In summary, the main differences between docker export and docker commit are:

docker export exports the container’s filesystem as a tar archive, excluding the image layers and container-specific metadata. It is primarily used for extracting files or data from a container.
docker commit creates a new image based on the changes made within a container, preserving the container’s state and configurations. It is useful for capturing the changes made to a container and creating a new image for future use or distribution.
When deciding which command to use, consider your specific use case. If you need to extract files or data from a container, docker export is appropriate. On the other hand, if you want to capture the changes made to a container and create a new image, docker commit is the suitable choice.