我对部署世界很陌生,当我尝试部署一个应用程序时,我就遇到了这个问题。我试图部署的应用程序由两个服务组成。第一个服务是一个人工智能模型,第二个是web应用程序。为了运行web应用程序,人工智能模型必须首先运行。这就是我试图制作的docker-compose.yml:
version: '3.8'
services:
max-image-caption-generator:
image: quay.io/codait/max-image-caption-generator
ports:
- "5000"
app:
build: .
depends_on:
- max-image-caption-generator
ports:
- "8088"以下是我的问题:
docker-compose.yml的定义正确吗?app首先运行the max-image-caption-generator?我能够从上面的文件构建,我可以卷曲http://localhost:5000,它给了我正确的html的人工智能模型,但我不能卷曲http://localhost:8088。它要么由对等方重置连接,要么无法连接到http://localhost:5000,这意味着AI模型没有运行。
发布于 2022-05-20 05:27:35
以下是你问题中的几个误解:
depends_on意味着app将在max-image-caption-generator之后运行,但是!Docker将不会检查max-image-caption-generator内部的服务是否正确启动。您必须添加healthcheck以确保max-image-caption-generator运行正常,然后向app添加条件service_healthy。http://localhost:5000,它不能。因为localhost:5000只能从Docker宿主访问,而不能从容器内部访问。您必须使用容器名称才能在容器之间进行通信。
你的船坞组合应该是:
version: '3.9'
services:
max-image-caption-generator:
image: quay.io/codait/max-image-caption-generator
ports:
- "5000"
# networks is optional parameter
networks:
service_network:
aliases:
- generator.hostname
# use it if you want to start app after max-image-caption-generator will be ready get requests
# healthcheck:
# test: ["CMD", "some_test_script", "--params"]
# interval: 30s
# timeout: 10s
# retries: 2
app:
build: .
# networks is optional parameter
networks:
- service_network
depends_on:
max-image-caption-generator:
# set this condition if you added healthcheck to max-image-caption-generator container
# condition: service_healthy
# this condition just run app after max-image-caption-generator, and no matter is max-image-caption-generator running properly or not
condition: service_started
ports:
- "8088"
# optional block that may be deleted (docker will use default network)
networks:
service_network:
name: service_network
driver: bridge
ipam:
driver: default
config:
- subnet: 10.0.10.240/28
gateway: 10.0.10.241在此之后,您将能够使用max-image-caption-generator url从容器连接到容器(如果没有提供networks块,则http://max-image-caption-generator:5000可以访问服务块(与服务密钥相同))
*这里您可以找到健康检查如何工作的信息。
https://stackoverflow.com/questions/72313384
复制相似问题