2016-12-30 86 views
0

我配置了我的Docker版本1.12的systemd以侦听端口:2375。Docker Daemon连接到插座上: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* 

然而,当我试着在我上运行的泊坞窗主机的终端使用“搬运工”的命令,我得到如下:

[[email protected] ~]# 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命令?

备注 我找到了以下配置,作为解决方法。然而,这似乎并不为多克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

我能想到的2种选择:

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 
+0

谢谢@Farhad Farahi,先生。第二种方法就像魅力一样。我在no_proxy下将0.0.0.0:2375添加到我的/ etc/environment中,因为我在此实例上使用了代理。再次感谢你的帮助。 – SSF