如何通过tcp-socker访问Docker守护程序? [英] How to access Docker daemon through tcp-socker?

查看:146
本文介绍了如何通过tcp-socker访问Docker守护程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经添加了

DOCKER_OPTS="-H tcp://0.0.0.0:2375"

到/ etc / default / docker使Docker API在主机上可以访问(我在Virtualbox中运行Docker一个Ubuntu虚拟机)。但是,当我尝试运行任何Docker命令时,我只收到这个错误消息:

to /etc/default/docker to make the Docker API accessible on my host machine (I'm running Docker in Virtualbox on an Ubuntu VM). However, when I try to run any Docker commands now, I just get this error message:

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

我已经尝试过sudo服务docker重新启动,重新启动机器,但没有任何工作。任何想法是什么问题?

I have tried sudo service docker restart, and restarted the machine, but nothing has worked. Any idea what the problem is?

推荐答案

要通过tcp套接字使用守护程序,选项 -H tcp://0.0.0.0:2375 应该添加到命令 docker (都为守护程序运行)。

To use the daemon through the tcp socket the option -H tcp://0.0.0.0:2375 should be added to the command docker (both for the daemon and run).

要使用其默认unix套接字访问守护程序,请确保Docker守护进程也从选项 -H = unix:///var/run/docker.sock 开始。

To access the daemon with its default unix socket make sure that the Docker daemon is also started with the option -H=unix:///var/run/docker.sock.

请注意,如果您不信任您所在的网络,则使用 tcp 是危险的。页面:

Note that using the tcp is dangerous if you do not trust the network you are in. Here is the doc from the man page:

   -H, --host=[unix:///var/run/docker.sock]: tcp://[host]:[port][path] to bind or unix://[/path/to/socket] to use.
     The socket(s) to bind to in daemon mode specified using one or more
     tcp://host:port/path, unix:///path/to/socket, fd://* or fd://socketfd.
     If the tcp port is not specified, then it will default to either 2375 when
     --tls is off, or 2376 when --tls is on, or --tlsverify is specified.

这篇关于如何通过tcp-socker访问Docker守护程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆