Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
接著我嘗試重新啟動docker:
1 2 3
sudo systemctl restart docker # 以下為output Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe"for details
要你執行systemctl status docker.service和journalctl -xe找詳細資料:
12月 16 23:47:44 mars systemd[1]: Starting LSB: Create lightweight, portable, self-sufficient containers.... 12月 16 23:47:44 mars docker[7032]: * /usr/bin/dockerd not present or not executable 12月 16 23:47:44 mars systemd[1]: docker.service: Control process exited, code=exited status=1 12月 16 23:47:44 mars systemd[1]: docker.service: Failed with result 'exit-code'. 12月 16 23:47:44 mars systemd[1]: Failed to start LSB: Create lightweight, portable, self-sufficient containers..
12月 17 00:08:53 mars systemd[1]: Starting LSB: Create lightweight, portable, self-sufficient containers.... 12月 17 00:08:53 mars docker[7724]: * Starting Docker: docker 12月 17 00:08:53 mars docker[7724]: ...done. 12月 17 00:08:53 mars systemd[1]: Started LSB: Create lightweight, portable, self-sufficient containers..
可以看到可以成功執行了~~
接著試試看nvidia-docker:
1 2 3 4 5 6 7 8 9 10 11 12 13
# Starting a GPU enabled container $ docker run --gpus all nvidia/cuda nvidia-smi
# Start a GPU enabled container on two GPUs $ docker run --gpus 2 nvidia/cuda nvidia-smi
# Starting a GPU enabled container on specific GPUs $ docker run --gpus device=1,2 nvidia/cuda nvidia-smi $ docker run --gpus device=UUID-ABCDEF,1 nvidia/cuda nvidia-smi
# Specifying a capability (graphics, compute, ...) for my container # Note this is rarely if ever used this way $ docker run --gpus all,capabilities=utilities nvidia/cuda nvidia-smi
如果成功會跟你在電腦中執行nvidia-smi的結果一樣。
因為docker-19.03已經支援使用NVIDIA GPUs作為運行中的設備了。
上面指令有加上--gpu的選項,如果你不要加,可以在Dockerfile上加上:
1 2 3 4
# 用來指定使用的gpu,和上面的--gpu相同功能 ENV NVIDIA_VISIBLE_DEVICES all # 用來指定計算資源,跟上面寫的一樣,這個功能很少用到 ENV NVIDIA_DRIVER_CAPABILITIES compute,utility