Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 53 additions & 17 deletions subscripts/2Install/6Install_Docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,42 @@
# Instructions for installing and configuring Nvidia Container Toolkit: https://docs.nvidia.com/jetson/orin-nano-devkit/user-guide/latest/setup_docker.html
# Note that the instructions for the toolkit are wrong. The correct package to install is nvidia-container-toolkit, not nvidia-container, see https://github.com/fly4future/install_script/pull/18 for more info.

sudo apt-get update
set -e

sudo apt-get install -y ca-certificates curl

# Check if we're running on an NVIDIA Jetson device.
if grep -q "NVIDIA Jetson" /proc/device-tree/model > /dev/null 2>&1; then
IS_JETSON=false
if grep -q "NVIDIA Jetson" /proc/device-tree/model >/dev/null 2>&1; then
IS_JETSON=true
fi

# Install Jetson dependencies if needed
if [ "$IS_JETSON" = true ]; then
echo "Installing NVIDIA Container Toolkit..."
sudo apt-get install -y nvidia-container-toolkit jq
fi

# Add Docker's official GPG key:
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Check whether Docker is already installed
if command -v docker >/dev/null 2>&1; then
echo "Docker is already installed:"
docker --version
DOCKER_ALREADY_INSTALLED=true
else
DOCKER_ALREADY_INSTALLED=false
fi

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
# Install Docker only if not already present
if [ "$DOCKER_ALREADY_INSTALLED" = false ]; then
echo "Installing Docker..."

# Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add Docker repository
sudo tee /etc/apt/sources.list.d/docker.sources >/dev/null <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Expand All @@ -27,11 +48,16 @@ Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker
sudo apt-get update

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

if grep -q "NVIDIA Jetson" /proc/device-tree/model > /dev/null 2>&1; then
sudo systemctl enable --now docker

echo "Docker successfully installed."
fi

if [ "$IS_JETSON" = true ]; then
echo "Configuring Docker to use NVIDIA Container Toolkit as the default runtime..."
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl daemon-reload
Expand All @@ -40,13 +66,23 @@ if grep -q "NVIDIA Jetson" /proc/device-tree/model > /dev/null 2>&1; then
sudo jq '. + {"default-runtime": "nvidia"}' /etc/docker/daemon.json | sudo tee /etc/docker/daemon.json.tmp
sudo mv /etc/docker/daemon.json.tmp /etc/docker/daemon.json
sudo systemctl restart docker

fi

echo "Add user $USER to docker group"
sudo usermod -aG docker $USER
# Add current user to docker group if not already a member
if ! groups "$USER" | grep -qw docker; then
echo "Adding $USER to docker group..."
sudo usermod -aG docker "$USER"
else
echo "$USER is already in the docker group."
fi

echo
echo "Installation complete."
echo

echo ""
echo "Docker installation complete. Please log out and log back in to apply the changes to your group and be able to use the docker command without sudo."
echo ""
if ! groups "$USER" | grep -qw docker; then
echo "Please log out and log back in for docker group membership to take effect."
fi

exit 0