[docker]Docker19.03初探

  • 参考:New Docker CLI API Support for NVIDIA GPUs under Docker Engine 19.03.0 Pre-Release

19.03版本无需安装nvidia-docker

  • Verify that NVIDIA card is detected 检查显卡
$ lspci -vv | grep -i nvidia
00:04.0 3D controller: NVIDIA Corporation GP100GL [Tesla P100 PCIe 16GB] (rev a1)
        Subsystem: NVIDIA Corporation GP100GL [Tesla P100 PCIe 16GB]
        Kernel modules: nvidiafb
  •  Installing NVIDIA drivers first 安装驱动,如果驱动已经安装跳过此步骤,安装驱动后重启
$ apt-get install ubuntu-drivers-common \
	&& sudo ubuntu-drivers autoinstall

$ reboot
  •  Installing NVIDIA Container Runtime 安装Runtime
$ cat nvidia-container-runtime-script.sh
 
curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \
  sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update



$ sh nvidia-container-runtime-script.sh

$ apt-get install nvidia-container-runtime

$ which nvidia-container-runtime-hook
/usr/bin/nvidia-container-runtime-hook

错误:E: 无法下载 http://ppa.launchpad.net/fcitx-team/nightly/ubuntu/dists/xenial/main/binary-amd64/Packages 404 Not Found 

解决方法:将对应的ppa删除即可

第一步:切换到对应的ppa目录:

cd /etc/apt/sources.list.d

第二步:在该目录下ls,即可以看到对应的无法下载的fcitx-team-ubuntu-nightly-xenial.list,删除该.list即可(安全起见,可以进行添加后缀.bak的备份)

命令如下:

mv fcitx-team-ubuntu-nightly-xenial.list fcitx-team-ubuntu-nightly-xenial.list.bak

具体如下图所示:

第三步:检查问题是否解决

在终端中输入命令:

sudo apt-get update

查看是否会出现如图1所示的问题

  •  Installing Docker 19.03 Beta 3 Test Build
$ curl -fsSL https://test.docker.com -o test-docker.sh 

$ sh test-docker.sh
  •  Verifying Docker Installation 
$ docker version
Client:
 Version:           19.03.0-beta3
 API version:       1.40
 Go version:        go1.12.4
 Git commit:        c55e026
 Built:             Thu Apr 25 02:58:59 2019
 OS/Arch:           linux/amd64
 Experimental:      false
Server:
 Engine:
  Version:          19.03.0-beta3
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.4
  Git commit:       c55e026
  Built:            Thu Apr 25 02:57:32 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.5
  GitCommit:        bb71b10fd8f58240ca47fbb579b9d1028eea7c84
 runc:
  Version:          1.0.0-rc6+dev
  GitCommit:        2b18fe1d885ee5083ef9f0838fee39b62d653e30
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

 错误:”Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.26/images/json: dial unix /var/run/docker.sock: connect: permission denied“

解决方法1:使用sudo获取管理员权限,运行docker命令

解决方法2:docker守护进程启动的时候,会默认赋予名字为docker的用户组读写Unix socket的权限,因此只要创建docker用户组,并将当前用户加入到docker用户组中,那么当前用户就有权限访问Unix socket了,进而也就可以执行docker相关命令。这一步骤需要重启电脑

sudo groupadd docker     #添加docker用户组
sudo gpasswd -a $USER docker     #将登陆用户加入到docker用户组中
newgrp docker     #更新用户组
docker ps    #测试docker命令是否可以使用sudo正常使用
  • Verifying –gpus option under docker run 
$ docker run --help | grep -i gpus
      --gpus gpu-request               GPU devices to add to the container ('all' to pass all GPUs)
  • Running a Ubuntu container which leverages GPUs
$ docker run -it --rm --gpus all ubuntu nvidia-smi
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
2746a4a261c9: Pull complete 
4c1d20cdee96: Pull complete 
0d3160e1d0de: Pull complete 
c8e37668deea: Pull complete 
Digest: sha256:250cc6f3f3ffc5cdaa9d8f4946ac79821aafb4d3afc93928f0de9336eba21aa4
Status: Downloaded newer image for ubuntu:latest
Mon Dec 23 10:18:40 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.40       Driver Version: 430.40       CUDA Version: N/A      |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1080    Off  | 00000000:01:00.0  On |                  N/A |
| 43%   37C    P0    40W / 180W |    266MiB /  8116MiB |     35%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

 

你可能感兴趣的:(Docker)