forked from codeperfectplus/HackScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_docker.sh
67 lines (52 loc) · 2.18 KB
/
setup_docker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Script to install Docker and Docker Compose on a Linux system
# status: tested
# published by: Deepak Raj
# published on: 2024-08-28
# Check if the script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or use sudo."
exit 1
fi
# Update package lists
echo "Updating package lists..."
apt-get update -y
# Install necessary packages
echo "Installing packages for Docker installation..."
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
# Add Docker’s official GPG key
echo "Adding Docker's official GPG key..."
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
# Set up the stable repository
echo "Setting up the Docker repository..."
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Update package lists again
echo "Updating package lists..."
apt-get update -y
# Install Docker
echo "Installing Docker..."
apt-get install -y docker-ce
# Fetch the latest Docker Compose version
echo "Fetching the latest Docker Compose version..."
LATEST_COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
# Install Docker Compose
echo "Installing Docker Compose version $LATEST_COMPOSE_VERSION..."
curl -L "https://github.com/docker/compose/releases/download/${LATEST_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# Set executable permissions for Docker Compose
echo "Setting executable permissions for Docker Compose..."
chmod +x /usr/local/bin/docker-compose
# Add the current user to the Docker group without needing to input
echo "Adding user to Docker group..."
usermod -aG docker "$SUDO_USER"
# Restart Docker to apply changes
echo "Restarting Docker..."
systemctl restart docker
# Display final message
echo "Docker and Docker Compose installation completed!"
echo "Docker Compose version $LATEST_COMPOSE_VERSION installed."
echo "You might need to log out and log back in to apply the group changes."
# Optional: Print Docker and Docker Compose versions
echo "Docker version:"
docker --version
echo "Docker Compose version:"
docker-compose --version