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

Management of xinetd-based services installed with RPM packages in Linux

Table of contents Preface 1. Startup management b...

How to use custom tags in html

Custom tags can be used freely in XML files and HT...

How to run py files directly in linux

1. First create the file (cd to the directory whe...

Solution to mysql prompt "got timeout reading communication packets"

Error message: user: 'root' host: `localh...

Example code for implementing random roll caller in html

After this roll call device starts calling the ro...

VMware15/16 Detailed steps to unlock VMware and install MacOS

VMware version: VMware-workstation-full-16 VMware...

How to reset your Linux password if lost

1. The startup menu is to move the cursor to the ...

How to compare two database table structures in mysql

During the development and debugging process, it ...

Let's talk in detail about how the NodeJS process exits

Table of contents Preface Active withdrawal Excep...

JavaScript to achieve skin effect (change background)

This article shares the specific code of JavaScri...

Detailed steps to install CentOS7 system on VMWare virtual machine

Pre-installation work: Make sure vmware workstati...

Detailed explanation of the use of Vue3 state management

Table of contents background Provide / Inject Ext...