Skip to content

erviker/DePortainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Docker Migration Script

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.

WORK IN PROGRESS

This script do not corrently work TODO:

  • all directorys are creatable by user if not make as sudo

πŸ“Œ Features

βœ… 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


πŸ”§ Prerequisites

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

πŸ“₯ Installation

  1. Clone this repository:
    git clone https://github.com/erviker/DePortainer.git
    cd DePortainer
  2. Make the script executable:
    chmod +x run.sh

πŸš€ Usage

Run the script on the old host:

./run.sh

Customization

The 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 migration

Modify them as needed before running the script.


πŸ“œ How It Works

  1. Checks & Sets Up SSH Access

    • Detects if an SSH key exists
    • Generates a new key if missing
    • Copies the key to the new host
  2. 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
  3. Migrates Docker Compose Stacks

    • Detects Compose stacks
    • Copies docker-compose.yml as compose.yaml
    • Transfers .env files if present
  4. Migrates Portainer Stacks (if applicable)

    • Extracts stack data from Portainer
    • Recreates stacks on the new host
  5. Transfers Volumes & Bind Mounts

    • Archives volumes and moves them to the new host
    • Recreates volumes and restores data
    • Syncs bind-mounted directories
  6. Restores & Restarts Containers

    • Deploys all transferred Compose stacks on the new host

πŸ›  Troubleshooting

  • 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

πŸ“œ License

This script is open-source under the MIT License.


πŸ‘¨β€πŸ’» Contributing

Feel free to submit issues or pull requests to improve the script!


πŸ“ž Support

For questions or suggestions, open an issue on this repository.

About

Move from Portainer to dockage host

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages