Docker export command
docker exportThe command is used to export the file system of a Docker container as a tar archive file.
docker exportThe command is mainly used to back up or migrate the container's file system, without including all layers and metadata of the Docker image.
Syntax
docker export [OPTIONS] CONTAINER
OPTIONS description:
-o, --output: Save the output to the specified file instead of outputting to standard output.
Export container file system:
docker export my_container
Export the file system of the container named my_container to standard output.
Save the exported file as a tar file:
docker export my_container > my_container_backup.tar
Export the filesystem of container my_container and save it to the file my_container_backup.tar.
Use the --output option to save the exported file:
shdocker export -o my_container_backup.tar my_container
Export the filesystem of container my_container and save it to the file my_container_backup.tar.
Example
Start a container:
docker run -d --name my_container ubuntu bash -c "echo hello > /hello.txt && sleep 3600"
Export the container's file system:
docker export my_container > my_container_backup.tar
View the contents of the exported tar file:
tar -tf my_container_backup.tar
Output:
hello.txt
Import file system into a new container:
cat my_container_backup.tar | docker import - my_new_image
Notes
docker exportOnly exports the container's file system, excluding Docker image layers, metadata, or runtime information.- If the container is running, the exported file system will be a snapshot of the container's current state.
- The exported tar file may be very large, depending on the size of the container's file system.
docker exportThe command is a useful tool for exporting a container's file system as a tar archive file. This is very useful for backing up, migrating, and analyzing container file systems. By using--outputoption, users can save the exported content to a specified file for easy management and use.
other extensions