#Docker Installation
$ sudo apt-get update
$ curl https://get.docker.com | sh \
&& sudo systemctl --now enable docker
$ 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#Nvidia-Docker Installation
$ sudo apt-get update
$ sudo apt-get install -y nvidia-docker2
$ sudo systemctl restart docker#Running sample docker
$ sudo docker run --rm --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smiIf you see this in your terminal after you have executed the command above, you have successfully installed nvidia-docker
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.60.11 Driver Version: 525.60.11 CUDA Version: 12.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... Off | 00000000:01:00.0 On | N/A |
| 30% 34C P8 25W / 320W | 1071MiB / 10240MiB | 1% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
Find the required docker tag - preferably from docker hub
#pulling docker image
$ sudo docker pull [docker_image]
#starting the container with gpu access in interactive mode
$ sudo docker run --gpus all -it [docker_image] bash
Example for pytorch docker
$ sudo docker pull pytorch/pytorch
$ sudo docker run --gpus all -it pytorch/pytorch bash
If you see this in your terminal after executing the above command, then you are inside the container and it works same as your normal terminal/command prompt with all the standard commands!!
root@<container-id>:/workspace# Now you can copy your codes or download codes from github and execute it as you would in a normal terminal/command prompt. Example:
root@<container-id>:/workspace#git clone <git repo>
root@<container-id>:/workspace#python script.pyTo exit from docker just type exit and hit enter.
root@<container-id>:/workspace#exit
user@yoursystem:~$ To List all dockers images in the local machine
docker images Check status of containers
docker ps -aTo retain all files and packages in the docker even after exiting
docker commit <container_id> <new-name>Delete container
docker rm <container_id>Delete all container/images/volumes at once
docker rm -f $(docker ps -a -q) #delete all containers
docker volume rm $(docker volume ls -q) #delete all volumes
docker rmi $(docker images -a -q) #delete all imagesCopy from Local disk to docker
docker cp <location in local system> container-id:<location in container>Example for moving foo.txt from local system to docker container
sudo docker cp ~/foo.txt thw8hb78bu:/workspace/Copy from docker to Local disk
sudo docker cp container-id:<location in container> <location in local system> List images
docker imagesTo initiate Jupyter Notebook from inside a docker
Step 1: Run this in your host system
docker run --gpus all -it -p 8888:8888 image:versionStep 2: Run this inside docker
jupyter notebook --ip 0.0.0.0 --port 8888 --no-browser --allow-rootfor jupyter notebook and
jupyter lab --ip 0.0.0.0 --port 8888 --no-browser --allow-rootfor jupyter lab
Step 3: Access the notebook through your desktop browser on http://localhost:8888 The notebook will prompt you for a token which was generated when you create the notebook which you will find from step 2.
docker run -v : -it /bin/bash
docker run -v /data/TMWIF-baselines/LAA-Net:/workspace --gpus 'all,capabilities=utility' -it laa_net /bin/bash