How to get know the tensorflow-serving URL?


I created a Dockerfile for tensorflow-serving as follows:

FROM tensorflow/serving

COPY /model_dir /models/model/

and I docker-compose it this way

    container_name: tfserving_classifier
    build: ./some_model_dir
      - 8501:8501

In the tensorflow-container, the model is located in /models/model/1

Here is how I tried to serve it

# server URL
url = 'http://localhost:8501/v1/models/model/1:predict'

def make_prediction(instances):
    data = json.dumps({"signature_name": "serving_default", "instances": instances.tolist()})
    headers = {"content-type": "application/json"}
    json_response =, data=data, headers=headers)
    predictions = json.loads(json_response.text)['predictions']
    return predictions

Here is the python code container message:

HTTPConnectionPool(host=’localhost’, port=8501): Max retries exceeded
with url: /v1/models/model/1:predict (Caused by
NewConnectionError(‘<urllib3.connection.HTTPConnection object at
0x7f315c19c4c0>: Failed to establish a new connection: [Errno 111]
Connection refused’))

I believe this is due to incorrect URL, how can I get the correct URL for my tensorflow-serving?

Here is the tensorflow-serving container message:

I tensorflow_serving/model_servers/] Running gRPC ModelServer at ...

I tensorflow_serving/model_servers/] Exporting HTTP/REST API at:localhost:8501 ...


localhost only reaches inside the container, use service name or container name of tensorflow to reach it from the script container


Answered By – Def Soudani

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published