Couldn't connect to the Docker daemon

使用 docker-compose up 有时会报如下错误:

#  docker-compose up
ERROR: Couldn't connect to Docker daemon at http://127.0.0.1:4243 - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

解决方法如下:

  1. 关闭docker服务
    # sudo service docker stop
    
  2. 通过守护进程运行
    # nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock &
    
  3. 检查端口 2375 是否已经有进程监听,然后配置环境变量 DOCKER_HOST
    netstat -anpt | grep 2375
    [xxx@docker ~]$ netstat -anpt | grep 2375
    (No info could be read for "-p": geteuid()=18922 but you should be root.)
    tcp6       0      0 :::2375                 :::*                    LISTEN      -
    
    编辑 ~/.bashrc,在最后一行添加如下内容
    export DOCKER_HOST=tcp://localhost:2375
    
  4. 再次运行 docker-compose up 即可。
36nu 分享编程知识及经验

已有账号?立即登录
微信公众号
关注36nu微信公众账号
获取最新编程知识及经验