├── LICENSE ├── README.md └── iran-docker.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Mohammadhossein Fakhraei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IRAN Docker 2 | 3 | A simple and powerful Bash script to simplify Docker usage on Iranian servers. 4 | 5 | ## Features 6 | 7 | * Easily switch between popular DNS providers (Shecan, Radar, Begzar, Google, etc.) 8 | * Automated Docker installation and setup 9 | * Apply Iranian Docker registry mirrors (ArvanCloud, Haiocloud, Iranserver, etc.) 10 | * DNS auto-backup before changes 11 | * Support for Debian/Ubuntu systems 12 | 13 | ## Usage 14 | 15 | ```bash 16 | git clone https://github.com/Linuxmaster14/iran-docker.git 17 | cd iran-docker 18 | chmod +x iran-docker.sh 19 | sudo ./iran-docker.sh 20 | ``` 21 | 22 | ## Menu Options 23 | 24 | 1) Set DNS 25 | 2) Install Docker 26 | 3) Update Docker 27 | 4) Set Docker Proxy 28 | 5) Exit 29 | 30 | ## Supported DNS Providers 31 | 32 | * Shecan 33 | * Radar 34 | * Electro 35 | * Begzar 36 | * DNSPro 37 | * 403 38 | * Google 39 | * Cloudflare 40 | 41 | ## Supported Docker Proxies 42 | 43 | * docker.kernel.ir 44 | * focker.ir 45 | * registry.docker.ir 46 | * docker.arvancloud.ir 47 | * docker.haiocloud.com 48 | * docker.iranserver.com 49 | * docker.mobinhost.com 50 | * hub.mecan.ir 51 | 52 | These proxies are applied to /etc/docker/daemon.json and the Docker service will be restarted automatically. 53 | 54 | ## License 55 | 56 | MIT – free for personal and commercial use. 57 | See [`LICENSE`](./LICENSE) for details. 58 | 59 | ## Author 60 | 61 | Made with [Linuxmaster14](https://github.com/Linuxmaster14) 62 | -------------------------------------------------------------------------------- /iran-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Iran Docker Management Script 4 | # Author: https://github.com/Linuxmaster14 5 | 6 | RED='\033[1;31m' 7 | GREEN='\033[1;32m' 8 | CYAN='\033[1;36m' 9 | NC='\033[0m' 10 | 11 | # Check if script is running with root privileges 12 | if [ "$EUID" -ne 0 ]; then 13 | echo -e "${RED}Error:${NC} Please run this script as root (use sudo)" 14 | exit 1 15 | fi 16 | 17 | # Main menu options 18 | main_menu_items=("Set DNS" "Install Docker" "Update Docker" "Set Docker Proxy" "Exit") 19 | 20 | # Available DNS providers and their servers 21 | dns_options=("Shecan" "Radar" "Electro" "Begzar" "DNSPro" "403" "DynX" "Google" "Cloudflare" "Reset to Default") 22 | declare -A dns_servers=( 23 | ["Shecan"]="178.22.122.100 185.51.200.2" 24 | ["Radar"]="10.202.10.10 10.202.10.11" 25 | ["Electro"]="78.157.42.100 78.157.42.101" 26 | ["Begzar"]="185.55.226.26 185.55.226.25" 27 | ["DNSPro"]="87.107.110.109 87.107.110.110" 28 | ["403"]="10.202.10.202 10.202.10.102" 29 | ["DynX"]="10.70.95.150 10.70.95.162" 30 | ["Google"]="8.8.8.8 8.8.4.4" 31 | ["Cloudflare"]="1.1.1.1 1.0.0.1" 32 | ["Reset to Default"]="127.0.0.53" 33 | ) 34 | 35 | # Iranian Docker registry mirrors 36 | registry_proxies=( 37 | "docker.kernel.ir" 38 | "focker.ir" 39 | "registry.docker.ir" 40 | "docker.arvancloud.ir" 41 | "docker.haiocloud.com" 42 | "docker.iranserver.com" 43 | "docker.mobinhost.com" 44 | "hub.mecan.ir" 45 | ) 46 | 47 | # DNS Management Functions 48 | backup_resolv() { 49 | cp /etc/resolv.conf "/etc/resolv.conf.bak.$(date +%Y%m%d_%H%M%S)" 50 | } 51 | 52 | # Set DNS servers based on user selection 53 | set_dns() { 54 | echo 55 | for i in "${!dns_options[@]}"; do 56 | echo " $((i + 1))) ${dns_options[$i]}" 57 | done 58 | echo " 0) Back" 59 | echo 60 | read -rp "Select DNS (0-${#dns_options[@]}): " dns_choice 61 | 62 | if [[ "$dns_choice" == "0" ]]; then return; fi 63 | if [[ ! "$dns_choice" =~ ^[0-9]+$ ]] || (( dns_choice < 1 || dns_choice > ${#dns_options[@]} )); then 64 | echo -e "${RED}Invalid DNS option${NC}"; return 65 | fi 66 | 67 | provider="${dns_options[$((dns_choice - 1))]}" 68 | dns_list="${dns_servers[$provider]}" 69 | 70 | # Create backup before making changes 71 | backup_resolv 72 | 73 | # Write new DNS configuration 74 | { 75 | echo "# DNS updated on $(date) by iran-docker script" 76 | for dns in $dns_list; do 77 | echo "nameserver $dns" 78 | done 79 | if [ "$provider" != "Reset to Default" ]; then 80 | echo "options edns0 trust-ad" 81 | grep "^search" /etc/resolv.conf 2>/dev/null 82 | fi 83 | } > /etc/resolv.conf 84 | 85 | echo -e "${GREEN}DNS updated to:${NC} $provider" 86 | } 87 | 88 | # Docker Management Functions 89 | 90 | install_docker() { 91 | # Check if Docker is already installed 92 | if command -v docker >/dev/null 2>&1; then 93 | version=$(docker version --format '{{.Server.Version}}' 2>/dev/null) 94 | if [ -n "$version" ]; then 95 | echo -e "${GREEN}Docker is already installed. Version: $version${NC}" 96 | return 97 | fi 98 | fi 99 | 100 | echo -e "${CYAN}Starting Docker installation...${NC}" 101 | 102 | # Update package lists 103 | echo -e "${GREEN}Updating package lists...${NC}" 104 | if ! apt-get update -qq >/dev/null 2>&1; then 105 | echo -e "${RED}Error:${NC} Failed to update package lists." 106 | return 1 107 | fi 108 | 109 | # Upgrade system packages 110 | echo -e "${GREEN}Upgrading system packages...${NC}" 111 | if ! apt-get upgrade -y -qq >/dev/null 2>&1; then 112 | echo -e "${RED}Error:${NC} Failed to upgrade packages." 113 | return 1 114 | fi 115 | 116 | # Install required dependencies 117 | echo -e "${GREEN}Installing required packages (curl)...${NC}" 118 | if ! apt-get install -y -qq curl >/dev/null 2>&1; then 119 | echo -e "${RED}Error:${NC} Failed to install prerequisites." 120 | return 1 121 | fi 122 | 123 | # Download and run Docker installation script 124 | echo -e "${GREEN}Downloading and installing Docker...${NC}" 125 | if ! curl -fsSL https://get.docker.com | sh >/dev/null 2>&1; then 126 | echo -e "${RED}Error:${NC} Docker installation script failed." 127 | return 1 128 | fi 129 | 130 | # Verify Docker installation 131 | if ! command -v docker >/dev/null 2>&1; then 132 | echo -e "${RED}Error:${NC} Docker command not found after installation." 133 | return 1 134 | fi 135 | 136 | # Get and display Docker version 137 | version=$(docker version --format '{{.Server.Version}}' 2>/dev/null) 138 | if [ -z "$version" ]; then 139 | echo -e "${RED}Error:${NC} Could not retrieve Docker version." 140 | return 1 141 | fi 142 | 143 | echo -e "${GREEN}Docker installed successfully. Version: $version${NC}" 144 | } 145 | 146 | # Update Docker to the latest version 147 | update_docker() { 148 | # Check if Docker is installed 149 | if ! command -v docker >/dev/null 2>&1; then 150 | echo -e "${RED}Docker is not installed.${NC} Please install it first." 151 | return 152 | fi 153 | 154 | echo -e "${CYAN}Updating Docker to the latest version...${NC}" 155 | 156 | # Download and run Docker installation script (also works for updates) 157 | echo -e "${GREEN}Downloading and installing Docker...${NC}" 158 | if ! curl -fsSL https://get.docker.com | sh >/dev/null 2>&1; then 159 | echo -e "${RED}Error:${NC} Docker update script failed." 160 | return 1 161 | fi 162 | 163 | # Display updated version 164 | version=$(docker version --format '{{.Server.Version}}' 2>/dev/null) 165 | echo -e "${GREEN}Docker updated successfully. Version: $version${NC}" 166 | } 167 | 168 | # Configure Docker to use Iranian registry mirrors 169 | set_docker_proxy() { 170 | echo 171 | echo -e "${CYAN}Select Docker Registry Mirror:${NC}" 172 | for i in "${!registry_proxies[@]}"; do 173 | echo " $((i + 1))) https://${registry_proxies[$i]}" 174 | done 175 | echo " 0) Back" 176 | echo 177 | read -rp "Select (0-${#registry_proxies[@]}): " proxy_choice 178 | 179 | if [[ "$proxy_choice" == "0" ]]; then return; fi 180 | if [[ ! "$proxy_choice" =~ ^[0-9]+$ ]] || (( proxy_choice < 1 || proxy_choice > ${#registry_proxies[@]} )); then 181 | echo -e "${RED}Invalid option${NC}"; return 182 | fi 183 | 184 | mirror="${registry_proxies[$((proxy_choice - 1))]}" 185 | 186 | # Create Docker configuration directory 187 | mkdir -p /etc/docker 188 | 189 | # Create daemon.json with registry mirror configuration 190 | echo -e "{\n \"registry-mirrors\": [\"https://$mirror\"]\n}" > /etc/docker/daemon.json 191 | 192 | # Restart Docker service to apply changes 193 | systemctl restart docker 194 | 195 | echo -e "${GREEN}Docker proxy set to:${NC} $mirror" 196 | } 197 | 198 | # Main Menu and Program Entry Point 199 | main_menu() { 200 | while true; do 201 | echo 202 | echo -e "${CYAN}Main Menu:${NC}" 203 | for i in "${!main_menu_items[@]}"; do 204 | echo " $((i + 1))) ${main_menu_items[$i]}" 205 | done 206 | echo 207 | read -rp "Select an option (1-${#main_menu_items[@]}): " choice 208 | 209 | case "$choice" in 210 | 1) set_dns ;; 211 | 2) install_docker ;; 212 | 3) update_docker ;; 213 | 4) set_docker_proxy ;; 214 | 5) echo -e "${CYAN}Bye.${NC}"; exit 0 ;; 215 | *) echo -e "${RED}Invalid choice${NC}" ;; 216 | esac 217 | done 218 | } 219 | 220 | # Start the program 221 | main_menu 222 | --------------------------------------------------------------------------------