从容器访问Docker远程API

编程入门 行业动态 更新时间:2024-10-23 19:28:14
本文介绍了从容器访问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 ,因此我正在使用 172.19.0.1:2375/images/json 来获取图像列表(从主机上, localhost:2375/images/json 可以正常工作.

The host address is 172.19.0.1, so I'm using 172.19.0.1:2375/images/json to get the list of images (from host, 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

本文发布于:2023-10-27 11:34:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533235.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   Docker   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!