|
1 | 1 | #! /bin/bash |
2 | | -set -eo pipefail |
| 2 | +set -euo pipefail |
3 | 3 |
|
4 | | -#Sets up docker, nvidia docker git-lfs and rocker which are used to clone and setup docker containers |
| 4 | +# Sets up docker, the NVIDIA Container Toolkit, git-lfs, pixi and uv, which are used |
| 5 | +# to clone and set up docker containers. |
| 6 | +# |
| 7 | +# Tested on Ubuntu 22.04 / 24.04 / 26.04. |
5 | 8 |
|
6 | | -#COPIED FROM OFFICIAL DOCKER INSTALL INSTRUCTIONS |
| 9 | +if [ "${EUID}" -eq 0 ]; then |
| 10 | + echo "Do not run this script as root / with sudo; it calls sudo itself where needed." >&2 |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +# Keep a sudo timestamp alive so the script does not stall halfway through. |
| 15 | +sudo -v |
| 16 | + |
| 17 | +# --------------------------------------------------------------------------- |
| 18 | +# DOCKER |
| 19 | +# Adapted from the official install instructions: |
7 | 20 | # https://docs.docker.com/engine/install/ubuntu/ |
| 21 | +# --------------------------------------------------------------------------- |
8 | 22 |
|
9 | | -#remove incorrect docker |
10 | | -for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove "$pkg"; done |
| 23 | +# Remove distro/podman packages that conflict with docker-ce. |
| 24 | +# `apt-get remove` on a package that is not installed is a no-op, so this is safe. |
| 25 | +sudo apt-get remove -y docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc |
11 | 26 |
|
12 | 27 | # Add Docker's official GPG key: |
13 | | -sudo apt update |
14 | | -sudo apt install -y ca-certificates curl |
| 28 | +sudo apt-get update |
| 29 | +sudo apt-get install -y ca-certificates curl |
15 | 30 | sudo install -m 0755 -d /etc/apt/keyrings |
16 | 31 | sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc |
17 | 32 | sudo chmod a+r /etc/apt/keyrings/docker.asc |
18 | 33 |
|
19 | 34 | # Add the repository to Apt sources: |
20 | 35 | # shellcheck disable=SC1091 |
| 36 | +UBUNTU_CODENAME="$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")" |
| 37 | + |
| 38 | +# Docker does not always publish a suite on release day. If this release is not |
| 39 | +# there yet, fall back to the most recent suite that is. |
| 40 | +if ! curl -fsSL -o /dev/null "https://download.docker.com/linux/ubuntu/dists/${UBUNTU_CODENAME}/Release"; then |
| 41 | + echo "WARNING: Docker has no apt suite for '${UBUNTU_CODENAME}' yet; falling back to 'noble'." >&2 |
| 42 | + UBUNTU_CODENAME=noble |
| 43 | +fi |
| 44 | + |
21 | 45 | echo \ |
22 | 46 | "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ |
23 | | - $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ |
| 47 | + ${UBUNTU_CODENAME} stable" | \ |
24 | 48 | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null |
25 | | -sudo apt update |
| 49 | +sudo apt-get update |
26 | 50 |
|
27 | 51 | # Install docker |
28 | | -sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin |
29 | | -#END OFFICIAL DOCKER INSTALL |
| 52 | +sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin |
| 53 | +# END OFFICIAL DOCKER INSTALL |
30 | 54 |
|
| 55 | +# Allow the current user to talk to the docker socket without sudo. |
| 56 | +# docker-ce already creates the group, so only create it if it is somehow missing. |
| 57 | +getent group docker > /dev/null || sudo groupadd docker |
| 58 | +sudo usermod -aG docker "$USER" |
31 | 59 |
|
| 60 | +# --------------------------------------------------------------------------- |
| 61 | +# NVIDIA CONTAINER TOOLKIT |
| 62 | +# https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html |
| 63 | +# Note: the old `nvidia-docker2` package is deprecated and is NOT needed. |
| 64 | +# --------------------------------------------------------------------------- |
32 | 65 |
|
33 | | -#INSTALL NVIDIA DOCKER |
34 | | -#https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html |
35 | | -curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \ |
36 | | - && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \ |
| 66 | +if command -v nvidia-smi > /dev/null && nvidia-smi -L > /dev/null 2>&1; then |
| 67 | + curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | \ |
| 68 | + sudo gpg --yes --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg |
| 69 | + curl -fsSL https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \ |
37 | 70 | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ |
38 | | - sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list |
39 | | -sudo apt update |
40 | | -sudo apt install -y nvidia-docker2 nvidia-container-toolkit |
41 | | -sudo nvidia-ctk runtime configure --runtime=docker |
42 | | -sudo systemctl restart docker |
43 | | - |
44 | | -sudo apt install -y git-lfs |
45 | | - |
46 | | -#Install rocker and rocker extensions which are used to launch the devcontainer |
| 71 | + sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list > /dev/null |
| 72 | + sudo apt-get update |
| 73 | + sudo apt-get install -y nvidia-container-toolkit |
| 74 | + sudo nvidia-ctk runtime configure --runtime=docker |
| 75 | + sudo systemctl restart docker |
| 76 | +else |
| 77 | + echo "No working NVIDIA driver detected (nvidia-smi failed); skipping NVIDIA Container Toolkit." |
| 78 | + echo "Install a driver first, e.g. 'sudo ubuntu-drivers install', reboot, then re-run this script." |
| 79 | +fi |
| 80 | + |
| 81 | +sudo apt-get install -y git-lfs |
| 82 | + |
| 83 | +# Install rocker and rocker extensions which are used to launch the devcontainer |
47 | 84 | # pip install rocker off-your-rocker git+https://github.com/blooop/deps_rocker |
48 | 85 |
|
49 | | -echo "testing docker install" |
50 | | - |
51 | | -docker run hello-world |
| 86 | +# --------------------------------------------------------------------------- |
| 87 | +# SMOKE TESTS |
| 88 | +# The `docker` group membership added above does not apply to the current shell |
| 89 | +# until the user logs out and back in, so run the tests with sudo. (Ubuntu 26.04 |
| 90 | +# removed `sg` and `newgrp`, so those are not an option.) |
| 91 | +# --------------------------------------------------------------------------- |
52 | 92 |
|
53 | | -echo "you may need to restart your machine" |
54 | | - |
55 | | -#INSTALL PIXI |
| 93 | +echo "testing docker install" |
| 94 | +sudo docker run --rm hello-world |
| 95 | + |
| 96 | +if command -v nvidia-ctk > /dev/null; then |
| 97 | + echo "testing nvidia docker install" |
| 98 | + # Plain ubuntu image matching the host release: the toolkit injects nvidia-smi |
| 99 | + # and the driver libraries from the host, so this avoids pinning a CUDA version. |
| 100 | + # shellcheck disable=SC1091 |
| 101 | + TEST_IMAGE="ubuntu:$(. /etc/os-release && echo "$VERSION_ID")" |
| 102 | + sudo docker run --rm --gpus all "${TEST_IMAGE}" nvidia-smi || \ |
| 103 | + echo "WARNING: GPU container test failed." |
| 104 | +fi |
| 105 | + |
| 106 | +# INSTALL PIXI |
56 | 107 | curl -fsSL https://pixi.sh/install.sh | bash |
57 | 108 | # shellcheck disable=SC2016 |
58 | | -echo 'eval "$(pixi completion --shell bash)"' >> ~/.bashrc |
| 109 | +grep -qF 'pixi completion --shell bash' ~/.bashrc || \ |
| 110 | + echo 'eval "$(pixi completion --shell bash)"' >> ~/.bashrc |
59 | 111 |
|
60 | | -#INSTALL UV |
| 112 | +# INSTALL UV |
61 | 113 | curl -LsSf https://astral.sh/uv/install.sh | sh |
62 | 114 |
|
63 | | -sudo groupadd docker |
64 | | -sudo usermod -aG docker "$USER" |
65 | | -newgrp docker || true |
| 115 | +echo |
| 116 | +echo "Done. Log out and back in (or reboot) so your 'docker' group membership applies" |
| 117 | +echo "to every new shell, and so pixi/uv are on your PATH." |
0 commit comments