[英]Using another image with the use of a docker-compose
I had a question regarding docker-compose files and having an image use another image through a requests.post
call?我有一个关于 docker-compose 文件的问题,以及让一个图像通过
requests.post
调用使用另一个图像? I am having trouble either connecting the two images together and/or accessing the images.我在将两个图像连接在一起和/或访问图像时遇到问题。
Here is what my docker-compose.yml looks like:这是我的 docker-compose.yml 的样子:
version: "3.7"
services:
cerberus:
image: "ctpelok77/ibmresearchaiplanningsolver"
ports:
- "4501:4501"
my-external-planner:
build: .
ports:
- "8000:8000"
I then use the following commands:然后我使用以下命令:
docker-compose up -d
docker run -it external-planner_my-external-planner
Inside the my-external-command
, I use the following line response = requests.post('http://cerberus:4501/planners/satisficing/seq-sat-cerberus', headers=headers, data=body_str)
;在
my-external-command
,我使用以下行response = requests.post('http://cerberus:4501/planners/satisficing/seq-sat-cerberus', headers=headers, data=body_str)
; however, this gives me a然而,这给了我一个
requests.exceptions.ConnectionError: HTTPConnectionPool(host='cerberus', port=4501): Max retries exceeded with
url: /planners/satisficing/seq-sat-cerberus (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f90eeb04510>: Failed to establish a new connection: [Errno -2] Name or service not known',))
I was wondering if I am not correctly connecting my images in the docker-compose or if I am incorrectly trying to access the images in my image?我想知道我是否没有正确连接 docker-compose 中的图像,或者我是否错误地尝试访问图像中的图像?
I was able to amend this issue by giving the services specific names and assigning them a shared network in the docker-compose.yml
file:我能够通过为服务提供特定名称并在
docker-compose.yml
文件中为它们分配共享网络来修改此问题:
version: "3.7"
services:
my-ibm-planner:
image: "ctpelok77/ibmresearchaiplanningsolver"
ports:
- "4501:4501"
container_name: "ibm-container"
networks:
- network-planner
tty: true
my-external-planner:
image: "docker.sift.net/tbessho/external-planner"
ports:
- "8000:8000"
networks:
- network-planner
container_name: "ext-plan"
tty: true
networks:
network-planner:
name: network-planner
along with changing the python script to use the following line:以及更改 python 脚本以使用以下行:
response = requests.post('http://ibm-container:4501/planners/satisficing/seq-sat-cerberus')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.