A command-line tool for exporting, importing, and checking Docker container layers.
- Export: Export Docker container's read-write layer, metadata, and Docker info to a file
- Import: Import exported file back to an existing container's read-write layer
- Check: Validate exported file integrity and compatibility
cargo build --releaseThe binary will be available at target/release/layer-tool.
cargo build --release --target=x86_64-unknown-linux-muslThe binary will be available at target/x86_64-unknown-linux-musl/release/layer-tool.
Export a container's read-write layer and metadata to a file:
layer-tool export <container_id> <output_file> [--compress]Examples:
# Export container to uncompressed file
layer-tool export my-container container-export.tar
# Export container to compressed file
layer-tool export my-container container-export.tar.gz --compressImport layer data from an export file to an existing container:
layer-tool import <input_file> <container_id> [--no-backup]Options:
--no-backup: Skip backing up existing layer before import (WARNING: This will permanently remove existing layer data)
Examples:
# Import from uncompressed file (with backup)
layer-tool import container-export.tar target-container
# Import from compressed file (automatically detected)
layer-tool import container-export.tar.gz target-container
# Import without backing up existing layer
layer-tool import container-export.tar target-container --no-backupValidate export file integrity and compatibility:
layer-tool check <input_file> [OPTIONS]Options:
--skip-image: Skip image SHA256 verification--skip-storage: Skip storage driver compatibility check--skip-os: Skip operating system compatibility check--skip-arch: Skip architecture compatibility check
Examples:
# Full check
layer-tool check container-export.tar
# Skip some compatibility checks
layer-tool check container-export.tar --skip-os --skip-archThe export file contains:
- Container metadata (JSON)
- Docker daemon information (JSON)
- Container's upper layer (tar archive)
- Optional gzip compression
- Docker daemon must be running and accessible
- Sufficient permissions to access Docker and container layer directories
- Target containers must exist for import operations
- The tool requires access to Docker daemon and container layer directories
- Export files may contain sensitive data from the container's file system
- Always validate export files before importing to production containers
- Use appropriate file permissions for export files
The tool provides detailed error messages for common issues:
- Container not found
- Permission denied
- Invalid export file format
- Checksum mismatches
- Compatibility issues
- Currently supports overlay2 storage driver
- Requires Docker CLI to be available
- Does not handle running containers (stop container before export/import)
- Limited to Linux systems
- Gather container metadata and Docker daemon information
- Locate the container's read-write layer directory (upper directory)
- Create a tar archive of the layer data
- Calculate checksums to ensure integrity
- Package metadata, Docker info, and layer data together
- Optionally compress the final file
- Read and validate the export file
- Extract metadata and Docker information
- Decompress if needed
- Backup the target container's existing layer (if it exists and is not empty, unless --no-backup is specified)
- Extract layer data to the target container's upper directory
- Verify checksums of the imported data
- Validate file structure and format
- Check metadata integrity
- Verify layer archive readability
- Perform compatibility checks with current Docker environment
- Generate detailed validation report
- Container Backup: Backup container's read-write layer for later restoration
- Container Migration: Migrate container state between different environments
- Development Environment: Share container state among development teams
- Testing: Create consistent test environment snapshots
- Disaster Recovery: Quickly restore containers to known states
Permission Errors
# Ensure user is in docker group
sudo usermod -aG docker $USER
# Or run with sudo
sudo layer-tool export container-name backup.tarContainer Not Found
# Check if container exists
docker ps -a
# Use full container ID or correct nameStorage Driver Incompatibility
# Check Docker storage driver
docker info | grep "Storage Driver"
# Use --skip-storage to bypass check (if safe)
layer-tool check backup.tar --skip-storage- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.