A minimalist yet powerful utility for backing up and restoring Docker images with ease.
go-backup-docker-image
helps you create portable archives of your Docker images, allowing you to store, transfer, and restore them when needed. Perfect for offline environments, backup strategies, or transferring images between airgapped systems.
- Flexible Input Methods: Accept image names from stdin, text files, or command arguments
- Concurrent Processing: Utilize worker pools for efficient multi-image operations
- Compression Support: Save space with built-in gzip compression
- Rich Metadata: Each backup includes detailed information about the image
- Comprehensive Management: Backup, restore, and list operations in one tool
- Detailed Reporting: Verbose output options for monitoring operations
go install -v github.com/Abhinandan-Khurana/go-backup-docker-image@latest
- Go 1.23 or later
- Docker installed and running
git clone https://github.com/Abhinandan-Khurana/go-backup-docker-image.git
cd go-backup-docker-image
go build -o go-backup-docker-image main.go
sudo mv go-backup-docker-image /usr/local/bin/
go-backup-docker-image backup nginx:latest
go-backup-docker-image restore docker-backups/nginx_latest-20230615-120530.tar.gz
go-backup-docker-image list
Back up Docker images to compressed or uncompressed tarballs.
go-backup-docker-image backup [IMAGE_NAME...] [flags]
Flag | Shorthand | Description |
---|---|---|
--dir |
-d |
Directory to store backups (default: "docker-backups") |
--workers |
-w |
Maximum number of concurrent workers (default: 3) |
--verbose |
-v |
Enable verbose logging |
--compress |
-c |
Compression type (gzip, none) (default: "gzip") |
--file |
-f |
Read image names from file |
--stdin |
-s |
Read image names from stdin |
Backup multiple images:
go-backup-docker-image backup nginx:latest redis:alpine postgres:13
Backup images listed in a file:
go-backup-docker-image backup --file images.txt
Backup images from stdin:
cat images.txt | go-backup-docker-image backup --stdin
Use uncompressed format:
go-backup-docker-image backup --compress none nginx:latest
Restore Docker images from tarballs.
go-backup-docker-image restore [TARBALL_PATH...] [flags]
Flag | Shorthand | Description |
---|---|---|
--verbose |
-v |
Enable verbose logging |
--file |
-f |
Read tarball paths from file |
--stdin |
-s |
Read tarball paths from stdin |
--workers |
-w |
Maximum number of concurrent workers (default: 3) |
Restore multiple image backups:
go-backup-docker-image restore backup1.tar.gz backup2.tar.gz
Restore images listed in a file:
go-backup-docker-image restore --file backups.txt
Display available image backups.
go-backup-docker-image list [flags]
Flag | Shorthand | Description |
---|---|---|
--dir |
-d |
Backup directory to list (default: "docker-backups") |
--verbose |
-v |
Show detailed information |
docker images --format "{{.Repository}}:{{.Tag}}" | grep -v "" > images.txt
go-backup-docker-image backup --file images.txt
On source machine:
go-backup-docker-image backup nginx:latest
scp docker-backups/nginx_latest-*.tar.gz user@destination:/path/
On destination machine:
go-backup-docker-image restore /path/nginx_latest-*.tar.gz
#!/bin/bash
# Save this as backup-images.sh
DATE=$(date +%Y%m%d)
BACKUP_DIR="/backup/docker-images/$DATE"
mkdir -p $BACKUP_DIR
docker images --format "{{.Repository}}:{{.Tag}}" | grep -v "" > $BACKUP_DIR/images.txt
go-backup-docker-image backup --file $BACKUP_DIR/images.txt --dir $BACKUP_DIR
"Error: Cannot connect to the Docker daemon"
- Ensure Docker is running with
docker ps
- Check if your user has permissions to access the Docker socket
"Error reading file: open images.txt: no such file or directory"
- Verify the file path is correct
- Check that the file has correct permissions
"Failed to save image: context deadline exceeded"
- For large images, try increasing the timeout or using uncompressed format
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Made with β€οΈ by Abhinandan-Khurana for Docker enthusiasts