'Could not connect to MLFlow model hosted on Docker
I hosted a model inside a docker container. On running the DockerFile, It runs the following command:
mlflow models serve -m model --port 8080 --no-conda
It serves the model succesfully , And I can now make calls to it. But, I keep getting Max retries exceeded with url
When I host the same model without using Docker(And follow the same steps), it works perfectly.
I use the following command to run the docker container
docker run -it --rm --network host imagename:random
I have also tried mapping port 8080, But still not able to get a response.
Not able to understand what the possible issues could be.
Dockerfile for reference
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
build-essential software-properties-common\
libboost-dev libboost-serialization-dev libssl-dev \
cmake vim\
wget \
make libbz2-dev libexpat1-dev swig python-dev
RUN add-apt-repository -y ppa:ubuntugis/ppa && apt-get -q update
RUN apt-get -y install gdal-bin libgdal-dev
RUN apt-get update
RUN apt install -y python3-pip
RUN pip3 install --upgrade pip
RUN pip install mlflow
RUN pip install pandas
RUN mkdir -p /tmp
COPY ./main.py /tmp/
COPY ./run.sh /tmp/
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
RUN chmod +x run.sh
CMD ./run.sh
Where, run.sh is
python3 main.py
mlflow models serve -m /tmp/mlflow_model --port 8080 --no-conda
When I run the commands of run.sh file outside of docker container, It is able to serve the model correctly,And I get the correct response.
Solution 1:[1]
The thing is that as for now, you are deploying a model inside your Docker container. So, the port 8080 is the one of the container and not the host machine.
You are suppose to run the container by saying to the host machine which port is linked to which one. This is called publishing a port. You can do it with the command -p.
If you look at docker doc :
$ docker run -p 127.0.0.1:80:8080/tcp ubuntu bash This binds port 8080 of the container to TCP port 80 on 127.0.0.1 of the host machine.
So for you, you should run with :
docker run -p 0.0.0.0:8080:8080 -it --rm --network host imagename:random
So basically, you connect the port 8080 of your container to the port 8080 of your host device.
Hope it helps !
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | LaZelk |