Docker守护程序连接到套接字:2375

时间:2016-12-30 03:57:40

标签: sockets docker systemd

我已将Docker版本1.12的systemd配置为侦听端口:2375。

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target

[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375
ExecReload=/bin/kill -s HUP
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

结果:

*tcp6       0      0 :::2375                 :::*                    LISTEN*

但是,当我尝试在主机的终端上使用'docker'命令时,我正在运行Docker,我得到以下内容:

    [root@docker1-12 ~]# docker images
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Even though the docker.service is actually running:

● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2016-12-30 14:50:53 AEDT; 1min 32s ago
     Docs: https://docs.docker.com
 Main PID: 4976 (dockerd)
   Memory: 21.1M
   CGroup: /system.slice/docker.service
           ├─4976 /usr/bin/dockerd -H tcp://0.0.0.0:2375
           └─4982 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --runtime do...

Dec 30 14:50:52 docker1-12 dockerd[4976]: time="2016-12-30T14:50:52.083736426+11:00" level=info msg="[graphdriver] using prior storage driver \"devicemapper\""
Dec 30 14:50:52 docker1-12 dockerd[4976]: time="2016-12-30T14:50:52.091254467+11:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Dec 30 14:50:52 docker1-12 dockerd[4976]: time="2016-12-30T14:50:52.095445562+11:00" level=info msg="Loading containers: start."
Dec 30 14:50:52 docker1-12 dockerd[4976]: time="2016-12-30T14:50:52.128643621+11:00" level=info msg="Firewalld running: true"
Dec 30 14:50:52 docker1-12 dockerd[4976]: time="2016-12-30T14:50:52.919797126+11:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
Dec 30 14:50:53 docker1-12 dockerd[4976]: time="2016-12-30T14:50:53.274835533+11:00" level=info msg="Loading containers: done."
Dec 30 14:50:53 docker1-12 dockerd[4976]: time="2016-12-30T14:50:53.275468481+11:00" level=info msg="Daemon has completed initialization"
Dec 30 14:50:53 docker1-12 dockerd[4976]: time="2016-12-30T14:50:53.275501250+11:00" level=info msg="Docker daemon" commit=7392c3b graphdriver=devicemapper version=1.12.5
Dec 30 14:50:53 docker1-12 dockerd[4976]: time="2016-12-30T14:50:53.285288956+11:00" level=info msg="API listen on [::]:2375"
Dec 30 14:50:53 docker1-12 systemd[1]: Started Docker Application Container Engine.

我该如何解决这个问题?即让docker在端口上监听端口:2375,同时能够在主机上本地运行docker命令吗?

注意 我找到了以下配置,作为一种解决方法。但是,这似乎不适用于Docker 1.12版:

Environment="DOCKER_OPTS=-H tcp://0.0.0.0:2375 --exec-opt native.cgroupdriver=cgroupfs"
ExecStart=/usr/bin/docker daemon -H fd://  \$DOCKER_OPTS

1 个答案:

答案 0 :(得分:3)

我可以想到两个选项:

1.更改您的systemd单位文件:

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

通过这种方式,您将在tcp上收听网络API来电,并在unix sock上收听本地docker cli

2.尝试使用docker cli进行连接时,请使用以下命令:

export DOCKER_HOST="tcp://0.0.0.0:2375"
docker ps

同样的效果:

sudo docker -H tcp://0.0.0.0:2375 ps