从容器访问Docker远程API

从容器访问Docker远程API

本文介绍了从容器访问Docker远程API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从容器内访问Docker远程API,因为我需要启动其他容器.

I'm trying to access Docker remote API from within a container because I need to start other containers.

主机地址为 172.19.0.1 ,因此我正在使用 http://172.19.0.1:2375/images/json 来获取图像列表(从主机上, http://localhost:2375/images/json 可以正常工作.

The host address is 172.19.0.1, so I'm using http://172.19.0.1:2375/images/json to get the list of images (from host, http://localhost:2375/images/json works as expected.

我拒绝了该连接,因为Docker(对于Windows)侦听的是 127.0.0.1 而不是 0.0.0.0 .

The connection is refused, I guess because Docker (for Windows) listens on 127.0.0.1 and not on 0.0.0.0.

我试图更改配置(从UI和 daemon.json ),添加以下条目:

I've tried to change configuration (both from UI and daemon.json) adding the entry:

"hosts": ["tcp://0.0.0.0:2375"]

,但是守护程序无法启动.如何访问api?

but the daemon fails to start. How can I access the api?

推荐答案

您可以在需要的容器内链接主机的/var/run/docker.sock.这样,您就不会通过开放的端口公开Docker Remote API.

You could link the host's /var/run/docker.sock within the container where you need it. This way, you don't expose the Docker Remote API via an open port.

请注意,它确实提供了对docker的类似root的访问.

Be aware that it does provide root-like access to docker.

-v /var/run/docker.sock:/var/run/docker.sock

这篇关于从容器访问Docker远程API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:48