解决CentOS6.4 Docker "Couldn't connect to Docker daemon ..." 问题

OS: CentOS6.4

#uname -r

2.6.32-504.1.3.el6.x86_64

安装完毕fig,并完成相应配置时执行如下命令出错(fig安装参见:http://www.fig.sh/):

#fig up
Couldn't connect to Docker daemon at http+unix://var/run/docker.sock - is it running? If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

 

查询相关网络资料,只有关于CentOS7的解决方案。

于是查看docker的启动脚本:vim /etc/rc.d/init.d/docker,在第50行可以看到启动docker时执行的命令如下:$exec -d $other_args $DOCKER_STORAGE_OPTIONS &>> $logfile &  

从执行命令可以看出,可以带一些自定义参数,如:$other_args $DOCKER_STORAGE_OPTIONS

为了解决目前遇到的问题,需要设置参数$other_args

vim /etc/sysconfig/docker-storage
# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d

other_args="-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock"

重启docker 服务并查看docker服务是否监听了4243端口:

#service docker restart
#netstat -anpt | grep 4243
tcp        0      0 127.0.0.1:4243              0.0.0.0:*                   LISTEN      7760/docker  

 

同时需要设置环境变量$DOCKER_HOST:

$vim ~/.bashrc
export DOCKER_HOST=tcp://localhost:4243

 

在执行fig up时已经ok。

 

参考:

Ubuntu上的解决办法:http://blog.csdn.net/kongxx/article/details/43481573#comments

CentOS7上的解决办法:https://docs.docker.com/articles/systemd/

 

posted @ 2015-02-08 15:16  nuccch  阅读(12422)  评论(2编辑  收藏  举报