Skip to content

Instantly share code, notes, and snippets.

@nathzi1505
Last active February 28, 2024 15:52
Show Gist options
  • Star 73 You must be signed in to star a gist
  • Fork 29 You must be signed in to fork a gist
  • Save nathzi1505/d2aab27ff93a3a9d82dada1336c45041 to your computer and use it in GitHub Desktop.
Save nathzi1505/d2aab27ff93a3a9d82dada1336c45041 to your computer and use it in GitHub Desktop.
Docker and Nvidia Docker installation in Ubuntu 20.04 LTS
# WARNING : This gist in the current form is a collection of command examples. Please exercise caution where mentioned.
# Docker
sudo apt-get update
sudo apt-get remove docker docker-engine docker.io
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
docker --version
# Put the user in the docker group
sudo usermod -a -G docker $USER
newgrp docker
# Nvidia Docker
sudo apt install curl
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
# Check Docker image
docker run --gpus all nvidia/cuda:10.0-base nvidia-smi
## Erase all Docker images [!!! CAUTION !!!]
# docker rmi -f $(docker images -a -q)
## Erase one Docker image [!!! CAUTION !!!]
# docker ps
# docker rmi -f image_id
## Running GUI Applications
xhost +local:docker
docker run --gpus all -it \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
nathzi1505:darknet bash
@MartinEls
Copy link

Thanks for the great write-up! Maybe it's a good idea to mention that you need nvidia-drivers on the base system and de-activate the ubuntu default VGA drivers:
https://www.server-world.info/en/note?os=Ubuntu_20.04&p=nvidia&f=1

@vsiegel
Copy link

vsiegel commented Dec 30, 2020

That script seems to be dangerous in its current form. That is certainly not intended.
From the file name install-docker.sh and the first couple of lines it is unambiguously a shell script to install something.
But part of the script is

## Erase all Docker images
docker rmi -f $(docker images -a -q)

This looks prone to unintended irreversible side effects possibly including data loss.
It seems to me it was meant as a command example, not as code to be executed.
I think the second line should start with an additional #.

@nathzi1505
Copy link
Author

nathzi1505 commented Dec 30, 2020

That script seems to be dangerous in its current form. That is certainly not intended.
From the file name install-docker.sh and the first couple of lines it is unambiguously a shell script to install something.
But part of the script is

## Erase all Docker images
docker rmi -f $(docker images -a -q)

This looks prone to unintended irreversible side effects possibly including data loss.
It seems to me it was meant as a command example, not as code to be executed.
I think the second line should start with an additional #.

Thank you so much @vsiegel for pointing it out. Most of my gists were created to serve mostly as code examples. Nevertheless, I still added a disclaimer, informing everyone.

Cheers and Happy New Year ✌🏻 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment