/
Docker

Docker



Installation - 20.04

For both NVidia, get the latest debs served on each group’s apt repo servers (i.e. don’t use Ubuntu’s):

Docker

$ sudo groupadd docker $ sudo usermod -aG docker $USER # Logout, Login $ docker run hello-world

Nvidia

# NVIDIA # https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#setting-up-nvidia-container-toolkit # NB: It uses their 18.04 repo for 20.04, this is OK $ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \ && curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \ && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \ sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list $ sudo apt-get update $ sudo apt-get install nvidia-container-toolkit $ sudo nvidia-ctk runtime configure --runtime=docker $ sudo systemctl restart docker $ sudo docker run --rm --runtime=nvidia --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi

Development Environment

 

These instructions are pretty dated. Better work went into groot_rocker, but these days, using vscode devcontainers instead.

Goal

A dockerised development environment that exactly emulates the usual workflows in a non-dockerised environment. The use case is to enable development for a version of the OS one currently doesn’t have installed (e.g. for Ubuntu Xenial or Focal when the installed operating system is Ubuntu Bionic) and the implicit, but critical requirement is that the docker container itself doesn’t subsume any of the tasks (e.g. dependency installation) of the workspace your are building.

Dockerfile

  • Arguments for the user (id/name) to be created within the docker environment

  • Provisions a workspace that can be bound from the local system in ~/workspace.

# Ubuntu images are listed at https://hub.docker.com/_/ubuntu/, can also use 'latest' FROM ubuntu:18.04 LABEL maintainer="Daniel Stonier" # Build Arguments ARG USER_ID=1000 ARG USER_NAME=bob ARG WORKSPACE_DIR="/home/\${USER_NAME}/workspace" # Bash Shell # Compatible User / Group # Basic operating system / development tools RUN adduser --quiet --disabled-password \ --shell /bin/bash --home /home/${USER_NAME} \ --gecos "Daniel Stonier" ${USER_NAME} \ --uid ${USER_ID} && \ apt-get update && \ apt-get -y install apt-utils bash-completion build-essential curl lsb-release sudo wget && \ echo "${USER_NAME} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \ usermod -a -G sudo ${USER_NAME} && \ echo "I'm grooty, you should be too" USER \${USER_NAME} # Use root to debug # USER root # Not sure if this is the best option, just what my non-docker user has, needed by some shell commands. ENV TERM xterm-256color SHELL ["/bin/bash", "--login", "-i"] WORKDIR \${WORKSPACE_DIR} # Used instead of CMD here so it can't be overridden on the command line ENTRYPOINT ["/bin/bash", "--login", "-i"]

Docker Image

#!/bin/bash # Catch the current $USER and transfer details to the Dockerfile so that shared # file permissions match # Dockerfile in this case is at /tmp/docker_tools/DockerFile # --rm: remove intermediate objects # -f: filename, if not 'DockerFile' # -t: a label for the image (name:tag) # .: path where the Dockerfile can be found DOCKER_IMAGE=groot:bionic docker image build \ --build-arg USER_ID=${USER_ID} \ --build-arg USER_NAME=${USER} \ --rm -t ${DOCKER_IMAGE} /tmp/docker_tools

Docker Run

#!/bin/bash # Docker Run Options: # -i : interactively run the image in a container # -rm : remove the container on exit, this loses changes! # -t : attach a pseudo tty, needed for e.g. stdin/stdout, vim etc DOCKER_IMAGE=groot:bionic CONTAINER_NAME=foo # convenient unique identifier (easier than hashes) LOCAL_WORKSPACE=/mnt/mervin/workspaces/devel/foo DOCKER_WORKSPACE=/home/${USER}/worskpace # <- this has to match what is configured in Dockerfile MOUNT_OPTIONS="--mount src=${LOCAL_WORKSPACE},target=${DOCKER_WORKSPACE},type=bind" docker container run ${MOUNT_OPTIONS} -i -t --name ${CONTAINER_NAME} ${DOCKER_IMAGE}

Management

# Installation sudo apt install docker.io # Useful Aliases alias docker-container-ls="docker container ls -a" alias docker-container-rm-all='docker container rm `docker container ls -a -q`' alias docker-container-rm-created="docker container rm $(docker ps -a -f status=created -q)" alias docker-container-rm-exited="docker container rm $(docker ps -a -f status=exited -q)" alias docker-image-ls="docker image ls" alias docker-image-rm-all='docker image rm `docker image ls -q`' alias docker-image-ls-dangling='docker images --filter "dangling=true"' alias docker-workspace-maliput="groot-docker-enter --distro=bionic --workspace=/mnt/mervin/workspaces/devel/maliput" # Other Useful One-Liners # Remove a container (use the id from docker ps) docker container rm 700351623 # Clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container) docker system prune # Additionally remove any stopped containers and all unused images (not just dangling) docker system prune -a

Docker + NVidia

Installation - 20.04

Docker

Nvidia

 

# Docker - was this available in the usual apt repos or did I get it somewhere else? $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - $ # NVIDIA

 

 

Related content