-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_install_script_v1.sh
74 lines (61 loc) · 2.17 KB
/
docker_install_script_v1.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
68
69
70
71
72
73
74
#!/bin/bash
# Function to check if a package is installed
is_package_installed() {
dpkg -l | grep -q $1
}
# Function to install a package if it's not already installed
install_package() {
if ! is_package_installed $1; then
echo "Installing $1..."
sudo apt-get install -y $1
else
echo "$1 is already installed."
fi
}
# Update package list
echo "Updating package list..."
sudo apt-get update
# Install dependencies
echo "Checking and installing dependencies..."
install_package "apt-transport-https"
install_package "ca-certificates"
install_package "curl"
install_package "software-properties-common"
# Add Docker’s official GPG key
echo "Adding Docker's official GPG key..."
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
# Add Docker repository
echo "Adding Docker repository..."
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update package list again
echo "Updating package list again..."
sudo apt-get update
# Install Docker
echo "Installing Docker..."
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Start and enable Docker service
echo "Starting and enabling Docker service..."
sudo systemctl start docker
sudo systemctl enable docker
# Verify Docker service is up and running
echo "Verifying Docker service status..."
if sudo systemctl is-active --quiet docker; then
echo "Docker service is up and running."
else
echo "Docker service is not running. Please check the logs for more information."
exit 1
fi
# Verify Docker installation by running a test container
echo "Verifying Docker installation by running a test container..."
sudo docker run hello-world
# Check if the test container ran successfully
if [ $? -eq 0 ]; then
echo "Docker installation verified successfully."
else
echo "Docker installation verification failed."
exit 1
fi
echo "Docker installation and verification completed successfully."