#!/bin/bash # Update and upgrade the system sudo apt update sudo apt upgrade -y # Add a new user to run Docker echo "Adding a new user to run Docker (username 'docker' is recommended)..." read -p "Enter username for the new Docker user: " USERNAME sudo useradd -m -s /bin/bash $USERNAME sudo usermod -aG docker $USERNAME echo "New user $USERNAME added to the docker group." # Install required dependencies sudo apt install -y apt-transport-https ca-certificates curl software-properties-common # Add Docker's official GPG key curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - # Add Docker repository sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" # Update package index again after adding Docker repository sudo apt update # Install Docker sudo apt install -y docker-ce # Install Docker Compose sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose # Install Portainer sudo docker volume create portainer_data sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data --restart always --name=portainer portainer/portainer-ce # Check if Portainer container is running if sudo docker ps | grep -q portainer; then echo "Portainer container is running successfully." else echo "Failed to start Portainer container." fi