linux - Docker 命令无法连接到 Docker 守护进程

标签 linux ubuntu docker daemon

我想转向 Docker,所以我刚刚开始搞乱它。我已经在 VirtualBox Ubuntu 15.10 (Wily Werewolf) 安装上安装了 Docker,并且作为 suggested here然后我尝试运行基本的nginx Docker 镜像:

$ docker run --name mynginx1 -P -d nginx
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

所以我检查了 Docker 是否正在运行:

$ sudo service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since vr 2015-11-06 08:41:48 CET; 15min ago
     Docs: https://docs.docker.com
 Main PID: 7542 (docker)
   CGroup: /system.slice/docker.service
           └─7542 /usr/bin/docker daemon -H fd://

nov 06 08:41:47 kramer65-VirtualBox systemd[1]: Starting Docker Application Container Engine...
nov 06 08:41:47 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:47.900410966+01:00" level=info msg="API ...ock"
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.033514149+01:00" level=info msg="Fire...lse"
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.141594321+01:00" level=info msg="Defa...ess"
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.416294436+01:00" level=warning msg="Y...it."
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.565507576+01:00" level=info msg="Load...rt."
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.567907022+01:00" level=info msg="Load...ne."
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.567945214+01:00" level=info msg="Daem...ion"
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.567969891+01:00" level=info msg="Dock....9.0
nov 06 08:41:48 kramer65-VirtualBox systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

这表明 Docker 守护进程实际上已经在运行,但可以肯定的是我只是手动启动了 Docker 守护进程:

$ sudo docker daemon
INFO[0000] API listen on /var/run/docker.sock           
INFO[0000] [graphdriver] using prior storage driver "aufs" 
INFO[0000] Firewalld running: false                     
INFO[0000] Default bridge (docker0) is assigned with an IP address XXX.XX.X.X/XX. Daemon option --bip can be used to set a preferred IP address 
WARN[0000] Your kernel does not support swap memory limit. 
INFO[0000] Loading containers: start.                   

INFO[0000] Loading containers: done.                    
INFO[0000] Daemon has completed initialization          
INFO[0000] Docker daemon                                 commit=76d6bc9 execdriver=native-0.2 graphdriver=aufs version=1.9.0

然后我再次尝试运行镜像,但结果相同:

$ docker run --name mynginx1 -P -d nginx
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

我尝试 sudo'ing 命令,但无济于事。我在这里做错了什么?

最佳答案

您需要将当前用户添加到 docker 组,如下所示:

sudo usermod -aG docker $(whoami)

然后注销并再次登录进入系统或重新启动系统。 通过 docker 版本

测试

有关如何安装 docker-engine 的更多信息,请关注 docker documentation

关于linux - Docker 命令无法连接到 Docker 守护进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33562109/

相关文章:

linux - 了解 ldd 输出 - 符号链接(symbolic link)

linux - 在没有 root 权限的情况下创建 PostgreSQL 数据库

mysql - 在docker-compose中找不到mysql数据库

macos - Boot2Docker 搜索不存在的 docker-bootstrap.sock

bash - docker容器nginx启动但一直挂起

linux - linux下生成全局唯一id的参数

linux - `environ` 结束后是什么?

python - 如何管理一堆python程序

linux命令删除或替换空格和特殊字符

php - 如何在 Linux 上的 xampp 安装中访问 mysql 和 php cli?