Detailed explanation of the process of setting up nvidia-docker environment on Linux server

Detailed explanation of the process of setting up nvidia-docker environment on Linux server

Docker is equivalent to a container, which can build a corresponding operating environment according to the operating environment you need. At this time, each environment is isolated from each other, so there will be no need to destroy the environment required by the original running code when a new code needs to be run. Each environment is isolated from each other, just like each container isolating it.

Since docker is only for running on CPU, for servers that need to run on GPU, it provides an nvidia-docker

sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP docker

As for how to build nvidia-docker on a server subaccount, each place on Baidu has different explanations. Therefore, after consulting relevant documents on Google, the method of building nvidia-docker on a server subaccount is listed as follows

Simply put, there are three steps to install nvidia-docker:

Install NVIDIA driver
Install docker
Install nvidia-docker

Install the graphics driver

For our server and even most servers, this step is necessary when installing the machine, so we will ignore this step directly. For specific questions, you can search on Baidu.

Install Docker

There are two versions of Docker available: Community Edition (CE) and Enterprise Edition (EE). Just like the NVIDIA graphics driver, we need to know the Linux version to choose the appropriate installation file. The following installation version is to install the community version on Ubuntu 16.04

The steps to install Docker are as follows

First, we need to remove the old version of Docker on your computer. If you are sure that this is the first time you install Docker on your machine, then this step can be omitted. Otherwise, you'd better execute the following command

sudo apt-get remove docker docker-engine docker.io

If docker is not installed on your machine, apt-get will tell you this.

Next, we will install Docker. It is recommended to install Docker from the repository so that when new versions are released, we can easily get updates from the repository.

In order to install docker from the repository, we need to first create a docker repository. Usually, we need to update the apt package

Update apt package index

sudo apt-get update

Then, install the package to allow apt to communicate over HTTP

sudo apt-get install \
  apt-transport-https \
  ca-certificates \
  curl \
  software-properties-common

Next, add Docker's official GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo pt-key add -

Verify that the following command outputs 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88

sudo apt-key fingerprint 0EBFCD88

Next, tell apt to use the stable repository by running the following command:

sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
(usb_release -cs) \
stable"

At this point, we have completed the establishment of the knowledge base. Next, we will update the apt package index and install Docker CE

sudo apt-get update && apt-get install docker-ce

Then after this step, just wait for the installation. It will take a long time to download. Keep waiting.

After installing docker, of course we need to verify whether our installation is successful

Use the famous hello-world image to test whether our docker installation is successful

sudo docker run hello-world

If you get the following interface, it proves that Docker is installed successfully

Install nvidia-docker

In the next step, we will complete our work by installing nvidia-docker, which is a plug-in in docker to help containers use GPU environments.

First, we need to remove the existing nvidia-docker

docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volum={} | xargs -r docker
sudo apt-get purge -y nvidia-docker

If you have not installed it before, you can skip this step.

Next, we will add the necessary repositories and then update the apt package index

curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
sudo apt-key add -

curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu16.04/amd64/nvidia-docker.list | \
sudo tee /etc/apt/sources.list.d/nvidia-docker.list

sudo apt-get update

Finally, we will install nvidia-docker

sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd

After the installation is successful, verify the nvidia-docker we installed

docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi

If this is your first time using the following command, you can see that Docker is trying to download something:

Here, the entire installation process is complete.

Breaking news! Once, after the server graphics card crashed, I reinstalled the graphics card driver and was surprised to find that my nvidia-docker environment was gone. However, I typed

docker version

It shows that docker exists, so you only need to follow the previous installation steps to install nvidia-docker. After the installation is successful, you will find that the experimental environment built according to the dockerfile is still there, fortunately!

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed tutorial for installing influxdb in docker (performance test)
  • Detailed explanation of Docker domestic image pulling and image acceleration registry-mirrors configuration modification
  • How to use Docker container to access host network
  • Detailed explanation of COPY and ADD commands in Dockerfile
  • How to write the best Dockerfile
  • Tutorial on installing Vagrant and Docker on Mac OS
  • Add port mapping after docker container starts
  • 10 bad habits to avoid in Docker container applications

<<:  Detailed tutorial for installing influxdb in docker (performance test)

>>:  Detailed explanation of multiple implementation methods of Mysql counting by conditions

Recommend

JavaScript to achieve full screen page scrolling effect

After I finished reading JavaScript DOM, I had a ...

Automatically install the Linux system based on cobbler

1. Install components yum install epel-rpm-macros...

Examples of implementing progress bars and order progress bars using CSS

The preparation for the final exams in the past h...

A nice html printing code supports page turning

ylbtech_html_print HTML print code, support page t...

Let's talk about destructuring in JS ES6

Overview es6 adds a new way to get specified elem...

Example code for circular hover effect using CSS Transitions

This article introduces Online preview and downlo...

How to control the startup order of docker compose services

summary Docker-compose can easily combine multipl...

Detailed explanation of Javascript Echarts air quality map effect

We need to first combine the air quality data wit...

How to use uni-app to display buttons and search boxes in the top navigation bar

Recently, the company is preparing to develop an ...

React internationalization react-i18next detailed explanation

Introduction react-i18next is a powerful internat...

Detailed explanation of how to detect and prevent JavaScript infinite loops

Table of contents Preface Fix infinite loop in fo...

How to use async and await in JS

Table of contents 1. async 2. await: 3. Comprehen...

Solution to the ineffective margin of div nested in HTML

Here's a solution to the problem where margin...

Using vue3 to implement counting function component encapsulation example

Table of contents Preface 1. The significance of ...