diff --git a/subscripts/2Install/6Install_Docker.sh b/subscripts/2Install/6Install_Docker.sh index 2f9e5f0..2b9a876 100755 --- a/subscripts/2Install/6Install_Docker.sh +++ b/subscripts/2Install/6Install_Docker.sh @@ -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 </dev/null < /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 @@ -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