我刚接触docker,当我创建一个端口号为8501的容器时,它工作得很好,但我需要有多个容器,而当我使用像8502这样的新端口号时,它就不能工作了。下面是我如何制作和使用容器,它被解释为here。我将函数称为make_prediction。这是正确的:
docker run -p 8501:8501 --name tfserving_classifier --mount type=bind,source=C:/Users/untitled6/voice_classifier/,target=/models/voice_classifier -e MODEL_NAME=voice_classifier -t tensorflow/servingdef make_prediction(instances,url):
data = json.dumps({"signature_name": "serving_default", "instances": instances.tolist()})
headers = {"content-type": "application/json"}
json_response = requests.post(url, data=data, headers=headers)
predictions = json.loads(json_response.text)['predictions']
return predictions
url = 'http://localhost:8501/v1/models/voice_classifier:predict'
predictions = make_prediction(x_test,url)但是,当我更改端口号以创建新的容器时,会显示一个错误:
docker run -p 8502:8502 --name tfserving_classifier1 --mount type=bind,source=C:/Users/untitled6/voice_classifier1/,target=/models/voice_classifier1 -e MODEL_NAME=voice_classifier1 -t tensorflow/servingdef make_prediction(instances,url):
data = json.dumps({"signature_name": "serving_default", "instances": instances.tolist()})
headers = {"content-type": "application/json"}
json_response = requests.post(url, data=data, headers=headers)
predictions = json.loads(json_response.text)['predictions']
return predictions
url = 'http://localhost:8502/v1/models/voice_classifier1:predict'
predictions = make_prediction(x_test,url)错误: requests.exceptions.ConnectionError:(‘连接已中止。’,RemoteDisconnected(‘无响应的远程端关闭连接’))
那么我如何才能拥有多个容器呢?我需要它们,因为我需要在我的应用程序中使用大约10个不同的模型。
发布于 2021-04-14 17:53:21
第二个-p端口号始终需要与容器内的程序正在侦听的端口号相匹配。这两个端口号不需要匹配。
如果主容器进程总是监听端口8501,那么您可以使用不同的端口号作为第一个端口号,并保持第二个端口号不变,从而重新映射它:
# vvvv fixed, matches what the application runs
docker run -p 8502:8501 ...
# ^^^^ your choice of externally-accessible port(另一个常见的变体是MySQL:标准的MySQL端口是3306,因此,如果您希望为数据库使用不同的主机端口,则需要一个像-p 3307:3306这样的选项;如果第二个端口号不是标准端口号,则无法以同样的方式访问数据库。)
https://stackoverflow.com/questions/67087960
复制相似问题