Advertisement
jcofer555

docker.img recreate

Apr 13th, 2025 (edited)
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.09 KB | None | 0 0
  1. STEPS TO RECREATE YOUR DOCKER.IMG:
  2.  
  3. Before starting confirm your templates are available on the flash drive at path /boot/config/plugins/dockerMan/templates-user, they will show as xml files. If checking the flash drive via windows then it would be just /config/plugins/dockerMan/templates-user
  4.  
  5. Also before starting run this command via terminal and if any results show please visit the discord to discuss before continuing:
  6. docker volume list -f "label=com.docker.volume.anonymous" -q | xargs -I{} docker container list --filter "volume={}"
  7. thanks to EDACerton for the command
  8.  
  9. 1. make note of the names of any custom networks you created with docker network create
  10. note: if you cannot start docker to confirm the names of the custom networks you used and you can't remember them then you can make a userscript with the code shown at the bottom to output the names of any custom networks you have. install the user scripts plugin from the apps page to make the script in
  11. note: if you hadn't created any custom networks you can skip this step
  12. optional: go to apps > previous apps and remove anything from your previous installs that you won't want to bring back after to make the next steps go smoother
  13. 2. stop docker at settings > docker by setting enable docker to no and hit apply
  14. suggested: backup the docker.img file using a file manager or via terminal (check path at settings > docker > Docker vDisk location)
  15. optional: change the vdisk size
  16. 3. in settings > docker put a check in the delete vdisk file box and hit delete at the bottom
  17. 4. in settings > docker change enable docker to yes and hit apply
  18. 5. create the custom docker network or networks you had prior by going to unraids terminal and type docker network create name changing name to the names you need it to be
  19. note: if you hadn't created any custom networks you can skip this step
  20. 6. go to apps, then previous apps and select all or select the ones you want and hit install
  21. 7. wait for it to finish and you're done now with a fresh docker.img
  22.  
  23. you won't lose any data and all settings for your containers will be retained unless your flash drive is corrupted which is why you check the flash drive for the xml templates before starting like mentioned at the top!!
  24.  
  25. BELOW IS THE THE USERSCRIPT DETAILS TO USE IF NEEDED, PUT EVERYTHING STARTING WITH #!/bin/bash IN THE SCRIPT AND THE RESULTS WILL DISPLAY IN THE SCRIPTS LOG
  26. note: when making a new script in userscripts plugin it will have the #!/bin/bash already, make sure you don't end up with it doubled at the top
  27. note: this pulls info from your templates on your flash drive so if you have old templates for things you don't run anymore those custom networks will show as well but it won't hurt anything to create them also
  28.  
  29. #!/bin/bash
  30.  
  31. # Temporary output file for the results of what custom network names were in use
  32. temporary_output_file="/mnt/user/system/custom_network_list.txt"
  33.  
  34. # ONLY CHANGE THE OUTPUT LOCATION ABOVE IF NEEDING A DIFFERENT LOCATION. THE FILE IS DELETED AUTOMATICALLY AT THE END OF THE SCRIPT
  35.  
  36. # DO NOT CHANGE ANYTHING BELOW HERE!!!
  37.  
  38. # Directory containing XML files
  39. input_dir="/boot/config/plugins/dockerMan/templates-user"
  40.  
  41. # Check if we can write to the temporary output file location
  42. if ! touch "$temporary_output_file" 2>/dev/null; then
  43.   echo "Error: Unable to write to $temporary_output_file. Check permissions, check if system share exists and what it's settings are."
  44.   exit 1
  45. fi
  46.  
  47. # Clear the output file
  48. > "$temporary_output_file"
  49.  
  50. # Loop through all XML files in the directory
  51. for file in "$input_dir"/*.xml; do
  52.   grep -oP '(?<=<Network>).*?(?=</Network>)' "$file" | grep -v "host" | grep -v "none" | grep -v "bridge" | grep -v "^br" | grep -v "^eth" | grep -v "^wg" | grep -v "container:"
  53. done | sort | uniq > "$temporary_output_file"
  54.  
  55. # Check if the output file is empty
  56. if [[ ! -s "$temporary_output_file" ]]; then
  57.   echo "No custom Docker networks detected."
  58. else
  59.   echo "Custom networks are as follows:"
  60.   while IFS= read -r line; do
  61.     echo "$line"
  62.   done < "$temporary_output_file"
  63. fi
  64.  
  65. # Removes the temporary output file
  66. rm "$temporary_output_file"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement