gpt4 book ai didi

docker - 容器在docker-compose中无法在网络中通信

转载 作者:行者123 更新时间:2023-12-02 18:36:52 27 4
gpt4 key购买 nike

我有一个docker-compose网络问题。因此,我使用ubuntutensorflowRstudio容器创建了共享空间,这在共享它们与主机之间的容量方面做得很好,但是当归结为使用彼此终端内部的一个容器的资源时一,我撞墙了。我只能在没有它的容器的终端中调用python。我的docker-compose.yaml:

# docker-compose.yml

version: '3'
services:

#ubuntu(16.04)
ubuntu:
image: ubuntu_base
build:
context: .
dockerfile: dockerfileBase
volumes:
- "/data/data_vol/:/data/data_vol/:Z"
networks:
- default
ports:
- "8081:8081"
tty: true

#tensorflow
tensorflow:
image: tensorflow_jupyter
build:
context: .
dockerfile: dockerfileTensorflow
volumes:
- "/data/data_vol/:/data/data_vol/:Z"
- .:/notebooks
networks:
- default
ports:
- "8888:8888"
tty: true

#rstudio
rstudio:
image: rstudio1
build:
context: .
dockerfile: dockerfileRstudio1
volumes:
- "/data/data_vol/:/data/data_vol/:Z"
networks:
- default
environment:
- PASSWORD=test
ports:
- "8787:8787"
tty: true


volumes:
ubuntu:
tensorflow:
rstudio:

networks:
default:
driver: bridge

我是一个 docker 新手,所以我不确定我的网络设置。就是说 docker inspect composetest_default(为compose创建的默认网络)表明容器已连接到网络。据我了解,在这种情况下,我应该能够在其他每个容器中自由调用一项服务,反之亦然:
"Containers": {
"83065ec7c84de22a1f91242b42d41b293e622528d4ef6819132325fde1d37164": {
"Name": "composetest_ubuntu_1",
"EndpointID": "0dbf6b889eb9f818cfafbe6523f020c862b2040b0162ffbcaebfbdc9395d1aa2",
"MacAddress": "02:42:c0:a8:40:04",
"IPv4Address": "192.168.64.4/20",
"IPv6Address": ""
},
"8a2e44a6d39abd246097cb9e5792a45ca25feee16c7c2e6a64fb1cee436631ff": {
"Name": "composetest_rstudio_1",
"EndpointID": "d7104ac8aaa089d4b679cc2a699ed7ab3592f4f549041fd35e5d2efe0a5d256a",
"MacAddress": "02:42:c0:a8:40:03",
"IPv4Address": "192.168.64.3/20",
"IPv6Address": ""
},
"ea51749aedb1ec28f5ba56139c5e948af90213d914630780a3a2d2ed8ec9c732": {
"Name": "composetest_tensorflow_1",
"EndpointID": "248e7b2f163cff2c1388c1c69196bea93369434d91cdedd67933c970ff160022",
"MacAddress": "02:42:c0:a8:40:02",
"IPv4Address": "192.168.64.2/20",
"IPv6Address": ""
}

史前史-我曾在docker-compose中尝试过 links:,但由于某些弃用警告而决定更改为 networks:。这是正确的做法吗?

Docker版本18.09.1

Docker-compose版本1.17.1

最佳答案

but when it comes down to using the resources of the one container inside the terminal of each other one, I hit a wall. I can't do as little as calling python in the terminal of the container that doesn't have it.



您不能使用Linux程序从另一个容器的容器的bin路径中访问,但是可以使用旨在通过网络从docker撰写文件中的任何容器通过网络进行通信的任何服务。

箱路径:
$ echo $PATH                                                                                                                                                                                              127 ↵
/home/exadra37/bin:/home/exadra37/bin:/home/exadra37/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

因此,此路径中未设计为通过网络进行通信的程序无法从其他容器中使用,并且需要安装在所需的每个容器中,例如 python

关于docker - 容器在docker-compose中无法在网络中通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54667878/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com