Creating a Dockerfile for a Custom Service - How to install local python packages in requirements.txt?

I have a local python package which can be installed through poetry. From what I can see, we have to do a git clone of the repo first, and then install it?

Could someone please share some type of resource that explains how to do this properly?

It seems like this Dockerfile needs to be in the ML repo where the model pth file is stored. So that when the docker image is created, the same environment can be used to set up the docker.

FROM pytorch/torchserve:latest-cpu

USER root # why?

COPY ./model-server/requirements.txt .

RUN apt-get install -y git poetry # for some reason this fails because it cannot find package Poetry 

# however, the following would look like:
RUN git clone


RUN poetry install 

RUN python3 -m pip install --no-cache-dir -r requirements.txt
USER model-server # why?

COPY path/to/local_file path/in/image # [ for all required files]
USER root # why ?
RUN printf "\nservice_envelope=json" >> /home/model-server/
RUN printf "\ninference_address=" >> /home/model-server/
RUN printf "\nmanagement_address=" >> /home/model-server/
USER model-server # why?


RUN torch-model-archiver -f   --model-name model_v1 --version 1.0 --serialized-file=/home/model-server/model.pth --model-file=/home/model-server/ --handler=/home/model-server/ --extra-files=/home/model-server/config.json,/home/model-server/conf.yaml --export-path=/home/model-server/model-store

CMD ["torchserve",      "--ncs", "--start",      "--ts-config=/home/model-server/",      "--models",      "model_v1.mar",      "--model-store",      "/home/model-server/model-store"]