Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?錯誤及解決方式

前言

這是筆者在使用docker ps時所碰到的錯誤。

錯誤訊息

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

解決方式

參考這個stackoverflow上的問答,只要使用以下指令即可:

systemctl start docker

Control Docker with systemd這個頁面說到:

Once Docker is installed, you need to start the Docker daemon. Most Linux distributions use systemctl to start services. If you do not have systemctl, use the service command.

即:在Docker安裝完成後,必須啟動Docker daemon. 大多數的Linux發行版使用的是sudo systemctl start docker,如果這個指令無法使用,可以用sudo service docker start來替代。

至於systemctl是什麼呢?
在說明這個之前,我們必須先了解什麼是init system

What is an init system?這篇文章中提到init system是在Fedora系統的kernel啟動後第一個運行的process。init system負責啟動所有必要的daemon, background process以及所有能讓OS正常運作的service。

How To Use Systemctl to Manage Systemd Services and Units中則說到systemctl是一個管理init system的工具。我們可以用

systemctl start xxx

來啟動某個服務,用:

systemctl stop xxx

來關閉服務。

另外,如果希望某個服務在開機時就自動啟動,可以使用:

systemctl enable xxx

如果希望某個服務不要在開機時自動啟動:

systemctl disable xxx

並且可以用以下指令查看某個服務的狀態:

systemctl status xxx

以下是systemctl status docker的輸出:

● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Mi 2018-12-05 08:02:38 CST; 1h 7min ago
Docs: https://docs.docker.com
Main PID: 14777 (dockerd)
CGroup: /system.slice/docker.service
├─14777 /usr/bin/dockerd -H unix://
├─14802 containerd --config /var/run/docker/containerd/containerd.toml --log-level info
├─15806 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8884 -container-ip 172.17.0.2 -container-port 8888
├─15820 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 6004 -container-ip 172.17.0.2 -container-port 6006
└─15828 containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/aa…
Dez 05 08:02:38 dcosa83 dockerd[14777]: time=“2018-12-05T08:02:38.301838904+08:00” level=info msg=“Daemon has completed initialization”
Dez 05 08:02:38 dcosa83 dockerd[14777]: time=“2018-12-05T08:02:38.722746579+08:00” level=info msg=“API listen on /var/run/docker.sock”
Dez 05 08:02:38 dcosa83 systemd[1]: Started Docker Application Container Engine.
Dez 05 08:09:33 dcosa83 dockerd[14777]: time=“2018-12-05T08:09:33.521489046+08:00” level=info msg=“Got signal to reload confi…n.json”
Dez 05 08:09:33 dcosa83 dockerd[14777]: time=“2018-12-05T08:09:33.524258342+08:00” level=info msg="Reloaded configuration: {…t-downl
Dez 05 08:10:39 dcosa83 dockerd[14777]: time=“2018-12-05T08:10:39.940999761+08:00” level=info msg=“Pull session cancelled”
Dez 05 08:11:21 dcosa83 dockerd[14777]: time=“2018-12-05T08:11:21.166063248+08:00” level=info msg=“shim containerd-shim start…d=15620
Dez 05 08:13:08 dcosa83 dockerd[14777]: time=“2018-12-05T08:13:08.154966977+08:00” level=info msg=“shim reaped” id=36df94ff00…98ae3a8
Dez 05 08:13:08 dcosa83 dockerd[14777]: time=“2018-12-05T08:13:08.164983634+08:00” level=info msg=“ignoring event” module=lib…Delete”
Dez 05 08:13:23 dcosa83 dockerd[14777]: time=“2018-12-05T08:13:23.487393678+08:00” level=info msg="shim containerd-shim start…d=15828
Hint: Some lines were ellipsized, use -l to show in full.

參考連結

Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?
Control Docker with systemd
How To Use Systemctl to Manage Systemd Services and Units
What is an init system?

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐