Getting Started with Docker

write first

Because the use of some assembly tools in the experiment requires a lower version of the operating system, I decided to use the docker virtual machine for operation (the host operating system is Ubuntu16.04). In addition, I have been busy with scientific research recently, and there are many things that have not been recorded in the blog. tidy up

introduce

Docker is actually a lightweight virtual machine. Unlike general virtual machines, there is no graphical interface, but it starts fast, occupies less resources and is small in size (for example, the Ubuntu+cuda image I use is only a few hundred M) . It can be understood as a state where ssh to someone else's computer only has a command line.

Install

Installation is also very simple. First, if you have docker on your computer before, you need to uninstall it first:

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

Then

curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -

Then install:

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
   $(lsb_release -cs) \
   stable"

# 从源里安装
sudo apt-get update
sudo apt-get install docker-ce

However, the installation may be very slow or not installed at all, then you need to modify the source.list

deb [arch=amd64] http://ipv6.mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ xenial stable

Finally, it will be used to join the docker group

sudo usermod -aG docker username

At this point, the docker installation is complete. If some of them are unsuccessful, please add sudo before the command.

NVIDIA-docker

The advantage of nvidia-docker is that it can share GPU resources

The first step is to uninstall the previous nvidia-docker

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

Then add the source to source.list (please add sudo if unsuccessful)

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

Install nvidia-docker2

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

After installation, we need to download the corresponding package:

Here is the official address

After finding the required package from here, use the docker pull nvidia/cuda: (version number) method to pull down the required image

last use

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

If you enter the GPU information, the image installation is successful

some commands

  1. View the image file: docker images

  2. run

    docker run -v /home/fish/GPU/docker/cuda7.5:/home/nvidia/7.5/ --name cuda7.5 -it nvidia/cuda:7.5-devel /bin/bash

    This is equivalent to mapping a directory of your current host to docker, and then define what name it is, -t is to specify which image you want to run, -i is the tty bound to the virtual machine, or it will end as soon as it runs. span

Principle explanation

Ten pictures to understand docker

Take a look at this tutorial, it's more intuitive.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326009450&siteId=291194637