All images, scripts and skills

Install Docker

bashruns as root

Installs Docker (engine, BuildKit and Compose) in a Docker-enabled workspace and waits for the daemon. Needs a workspace created with the Docker-enabled option.

What it runs

The whole script, exactly as it will execute in your workspace. Nothing is hidden — read it before you run it.

#!/bin/bash
# Install Docker in a Docker-enabled DevGrail workspace.
#
# Installs Ubuntu's own Docker packages: the engine (docker.io), BuildKit
# (docker-buildx) and Compose (docker-compose-v2). The workspace already has
# what Docker needs to run in it: /etc/docker/daemon.json, the storage driver
# and a supervisor that starts the daemon as soon as it is installed, and again
# after every restart. Following any other guide (Docker's own docker-ce
# instructions, say) works just as well.
#
# Runs as root. Safe to run again: it installs whatever is missing and checks
# that the daemon answers.
set -euo pipefail

# DevGrail marks a Docker-enabled workspace with DEVGRAIL_NESTED_DOCKER=1 in the
# container's environment. A script run from Scripts inherits it, but plain
# `sudo bash install-docker.sh` in a terminal does not: sudo resets the
# environment. PID 1 still carries the container's own, and this runs as root,
# which may read it. (grep without -q reads to the end, so tr never gets SIGPIPE
# and pipefail sees grep's answer.)
nested_docker() {
    [ "${DEVGRAIL_NESTED_DOCKER:-}" = 1 ] && return 0
    [ -r /proc/1/environ ] &&
        tr '\0' '\n' < /proc/1/environ | grep -x 'DEVGRAIL_NESTED_DOCKER=1' >/dev/null
}

if ! nested_docker; then
    echo "This is not a Docker-enabled workspace, so Docker cannot run in it." >&2
    echo "Create a new workspace with the \"Docker-enabled workspace\" option instead;" >&2
    echo "an admin has to allow your account to create them first." >&2
    exit 1
fi

export DEBIAN_FRONTEND=noninteractive
echo "Installing Docker (docker.io, docker-buildx, docker-compose-v2)..."
apt-get update
apt-get install -y --no-install-recommends docker.io docker-buildx docker-compose-v2
# So `docker` works without sudo in new shells too. The daemon already gives
# its socket to dev's group, so this only matters to guides that expect it.
usermod -aG docker dev || true

echo "Waiting for the Docker daemon to start..."
for _ in $(seq 1 60); do
    if docker info >/dev/null 2>&1; then
        docker version
        echo
        echo "Docker is ready. Try: docker run --rm hello-world"
        exit 0
    fi
    sleep 2
done

echo "The Docker daemon did not answer within two minutes." >&2
echo "Its log is /var/log/devgrail-dockerd.log:" >&2
tail -n 30 /var/log/devgrail-dockerd.log >&2 || true
exit 1

How to get it

Open your DevGrail workspace, go to Scripts → Official scripts, and choose Download. It is copied into your own library, where you can edit it, run it, or set it as a workspace default — the copy is yours, and later changes here do not touch it.