***Ultimate Guide***: How to Recreate Docker.img in Unraid (2024) - Zero Data Loss Method

Overview

This document provides a comprehensive guide for recreating the Docker.img file on Unraid while preserving container configurations and custom networks. This process can be useful for maintenance, troubleshooting, or resizing the Docker virtual disk.

Prerequisites

  • Administrative access to Unraid
  • Basic understanding of Docker networking
  • Terminal access to Unraid server
  • Backup of critical data (recommended)

Important Notes

  • This procedure will not result in data loss if followed correctly
  • Container configurations will be preserved
  • All custom networks will need to be recreated

Detailed Procedure

1. Document Custom Networks

Important: Complete this step before proceeding if you have custom networks.

Option A: If Docker is Running

docker network ls

Make note of all custom networks (excluding default networks like ‘bridge’, ‘host’, and ‘none’).

Option B: If Docker is Not Running

Use the provided network discovery script (detailed in Section V).

2. Stop Docker Service

  1. Navigate to Settings > Docker
  2. Set “Enable Docker” to “No”
  3. Click “Apply”

3. Backup (Optional but Recommended)

# Using terminal
cp /mnt/user/system/docker/docker.img /mnt/user/backups/docker.img.bak

# Alternative: Use Unraid's file manager to create a backup

4. Remove Existing Docker.img

  1. In Settings > Docker:
    • Enable “Delete VDISK file”
    • Click “Apply”
    • Verify the docker.img file is removed

5. Optional Cleanup

  1. Navigate to Apps > Previous Apps
  2. Review and remove unnecessary containers
  3. Document any specific container configurations you wish to preserve

6. Reinitialize Docker

  1. Return to Settings > Docker
  2. Set “Enable Docker” to “Yes”
  3. Configure desired vdisk size (if changing)
  4. Click “Apply”

7. Recreate Custom Networks

For each custom network previously documented:

docker network create <network_name>

8. Restore Containers

  1. Navigate to Apps > Previous Apps
  2. Select desired containers for reinstallation
  3. Click “Install Selected”
  4. Monitor the installation progress

9. Verify Installation

  1. Check container status
  2. Verify network connectivity
  3. Test container functionality
  4. Review logs for any errors

V. Custom Network Discovery Script

Use this script if Docker is unavailable and you need to identify custom networks.

#!/bin/bash

# Configuration
OUTPUT_FILE="/mnt/user/data/docker_networks.txt"
INPUT_DIR="/boot/config/plugins/dockerMan/templates-user"

# Clear existing output
> "$OUTPUT_FILE"

# Process XML files and extract network information
for file in "$INPUT_DIR"/*.xml; do
    grep -oP '(?<=<Network>).*?(?=</Network>)' "$file" | \
    grep -v "host" | \
    grep -v "bridge" | \
    grep -v "br0" | \
    grep -v "container:" \
    done | sort | uniq > "$OUTPUT_FILE"

echo "Network information exported to $OUTPUT_FILE"

Script Usage

  1. Save the script with a .sh extension
  2. Make it executable:
    chmod +x script_docker.sh
    
  3. Run the script:
    ./script_docker.sh
    
  4. Check the output file for custom network names

Troubleshooting

Common Issues

  1. Container Won’t Start

    • Verify network assignments
    • Check container logs
    • Confirm port mappings
  2. Missing Networks

    • Review network discovery script output
    • Check container network dependencies
    • Verify network creation commands
  3. Configuration Issues

    • Compare against documented settings
    • Review container templates
    • Check volume mappings

Best Practices

  1. Always backup before starting
  2. Document all custom configurations
  3. Take screenshots of critical settings
  4. Test container functionality after restoration
  5. Maintain detailed network documentation
  6. Regular maintenance and cleanup

Support

For additional assistance:

  • Consult Unraid forums
  • Review Docker documentation
  • Check container-specific documentation

Version Information

  • Last Updated: 2024
  • Tested on: Unraid 6.x
  • Docker version: 20.x and later
2 Likes