Skip to content

Instantly share code, notes, and snippets.

@katox
Last active November 16, 2025 09:53
Show Gist options
  • Select an option

  • Save katox/687e81a8b7d2e41908c695de33e706e9 to your computer and use it in GitHub Desktop.

Select an option

Save katox/687e81a8b7d2e41908c695de33e706e9 to your computer and use it in GitHub Desktop.
Export the final filesystem of a docker image into a directory
#!/bin/sh -e
# Function to display help message
show_help() {
echo "Usage: $0 <image_name> <destination_path>"
echo ""
echo " image_name The name of the Docker image."
echo " destination_path The path on your host system where you want to save the filesystem of the image."
}
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
show_help
exit 1
fi
IMAGE_NAME=$1
DESTINATION_PATH=$2
mkdir -p "$DESTINATION_PATH"
# Create a temporary container from the image
docker create --name temp_container $IMAGE_NAME
# Export the filesystem contents to a tar file using docker export -o
docker export $(docker ps -aqf "name=temp_container") | tar -C $DESTINATION_PATH -xf -
# Remove the temporary container
docker rm temp_container
echo "Image filesystem contents exported to ${DESTINATION_PATH}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment