The Docker export command
docker export This command exports a Docker container's filesystem as a tar archive.
docker export It is mainly used to back up or migrate a container's filesystem, excluding the image's layers and metadata.
Syntax
docker export [OPTIONS] CONTAINER
OPTIONS description:
-o, --output: Save the output to a specified file instead of standard output.
Export a container's filesystem:
docker export my_container
Export the filesystem 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.
Save the exported file using the --output option:
sh
docker 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 filesystem:
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 the filesystem into a new container:
cat my_container_backup.tar | docker import - my_new_image
Notes
docker exportIt only exports the container's filesystem, excluding the Docker image's layers, metadata, or runtime information.- If the container is running, the exported filesystem will be a snapshot of the container's current state.
- The exported tar file can be very large, depending on the size of the container's filesystem.
docker export This command is a useful tool for exporting a container's filesystem as a tar archive. It is very useful for backing up, migrating, and analyzing a container's filesystem. By using the --output option, users can save the exported content to a specified file for easy management and use.
Docker Command Reference