This script automates the process of migrating Docker containers, volumes, and Portainer stacks from one host to another host running dockage, supporting both Red Hat-based (Rocky, RHEL, CentOS) and Debian-based (Ubuntu, Debian) distributions.
This script do not corrently work TODO:
- all directorys are creatable by user if not make as sudo
β
Automatically sets up SSH key-based authentication if needed
β
Ensures the new host has Docker & Docker Compose installed and running
β
Supports both Red Hat and Debian-based operating systems
β
Adds the specified user to the Docker group if missing
β
Migrates all Docker Compose stacks (renaming docker-compose.yml β compose.yaml)
β
Extracts and transfers Portainer stacks (but does not move Portainer itself)
β
Transfers Docker volumes and bind mounts
β
Starts all migrated containers on the new host
Ensure the following:
- You have SSH access to both the old and new host
- The new host is running Rocky Linux, RHEL, CentOS, Ubuntu, or Debian
- The script is executed with a user that has sudo privileges
- Clone this repository:
git clone https://github.com/erviker/DePortainer.git cd DePortainer - Make the script executable:
chmod +x run.sh
Run the script on the old host:
./run.shThe script defines the following variables:
USER="erviker" # Change this to the target user on the new host
NEW_HOST="$USER@new-host" # Change to the new host's IP or hostname
REMOTE_COMPOSE_DIR="/opt/dockage" # Directory to store Compose files on new host
EXCLUDE_VOLUMES=("portainer_data") # Volumes to exclude from migrationModify them as needed before running the script.
-
Checks & Sets Up SSH Access
- Detects if an SSH key exists
- Generates a new key if missing
- Copies the key to the new host
-
Prepares the New Host
- Ensures Docker & Docker Compose are installed and running
- Detects whether the OS is Red Hat-based or Debian-based and installs the correct packages
- Adds the user to the Docker group
- Creates the necessary
/opt/dockage/directory
-
Migrates Docker Compose Stacks
- Detects Compose stacks
- Copies
docker-compose.ymlascompose.yaml - Transfers
.envfiles if present
-
Migrates Portainer Stacks (if applicable)
- Extracts stack data from Portainer
- Recreates stacks on the new host
-
Transfers Volumes & Bind Mounts
- Archives volumes and moves them to the new host
- Recreates volumes and restores data
- Syncs bind-mounted directories
-
Restores & Restarts Containers
- Deploys all transferred Compose stacks on the new host
- If SSH authentication fails, manually add your SSH key:
ssh-copy-id $USER@new-host - If Docker is not found on the new host, install it manually:
# For Red Hat-based systems sudo dnf install -y docker docker-compose-plugin # For Debian-based systems sudo apt update && sudo apt install -y docker.io docker-compose sudo systemctl enable --now docker
- Ensure the user is in the Docker group:
sudo usermod -aG docker $USER
This script is open-source under the MIT License.
Feel free to submit issues or pull requests to improve the script!
For questions or suggestions, open an issue on this repository.