如何通过tcp-socker访问Docker守护进程?

我已经添加了

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

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

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

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

要通过tcp套接字使用守护程序,应将选项-H tcp://0.0.0.0:2375添加到命令-H tcp://0.0.0.0:2375 (对于daemonrun )。

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


请注意,如果您不信任您所在的networking,则使用tcp是非常危险的。以下是手册页中的文档:

  -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.