Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which port number to choose for docker container

I'm new to docker and when I make a container with port number 8501 it works fine, but I need to have multiple containers and when I use a new port number like 8502 it doesn't work. here is how I make and use the container which was explaied here. I call the function make_prediction. this works correcty:

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/serving
def 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)

But when I change the port number to make a new container an error is shown:

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/serving

def 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)

The error: requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

So how can I have multiple containers? I need them because I need to use about 10 different models in my application.

like image 291
mina Avatar asked Oct 24 '25 19:10

mina


1 Answers

The second -p port number always needs to match the port number the program inside the container is listening on. The two port numbers don't need to match.

If the main container process always listens on port 8501, then you can remap it by using a different port number for the first port number, and keeping the second port number the same:

#                  vvvv fixed, matches what the application runs
docker run -p 8502:8501 ...
#             ^^^^ your choice of externally-accessible port

(One more common variant of this is around MySQL: the standard MySQL port is 3306, so if you want a different host port for your database, you need an option like -p 3307:3306; if the second port number isn't the standard port number the database will be unreachable in this same way.)

like image 139
David Maze Avatar answered Oct 27 '25 09:10

David Maze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!