3

I am trying to create a docker image to make it run as a server for serving a model in pytorch.

I converted the .pt model file to .MAR file in my local machine and i copied the .MAR file inside the docker image. I created a dockerfile:

FROM ubuntu:18.04
ENV TZ=Asia/Shanghai
ENV DEBIAN_FRONTEND noninteractive 
RUN apt-get update \
    && apt-get install --yes --no-install-recommends \
    tzdata

RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime\ 
    && echo ${TZ} > /etc/timezone \
    && dpkg-reconfigure -f noninteractive tzdata

RUN apt-get install python3 python3-dev python3-pip openjdk-11-jre-headless git wget curl -y
RUN python3 -m pip install torch torchvision torch-model-archiver torchserve==0.2.0
COPY densenet161.mar /model_store/
CMD torchserve --start --model-store model_store --models densenet161=densenet161.mar
EXPOSE 8080

I was able to create the image but I was not able to access that container when I tried to open the image and run the code it works

docker exec -it 4b126bd87f21 sh

# torchserve --start --ncs --model-store model_store --models densenet161.mar

The server is running. When I run the docker image it is not working. Docker container is running but I was not able to access the server.

I don't know what is the problem.

Trong Van
  • 374
  • 1
  • 13
mohamed fazil
  • 71
  • 1
  • 3
  • What kind of error do you get? If it is like not able to access host, then try adding `--net host` command when running the container using `docker run` – eroot163pi May 06 '21 at 10:40
  • answer here : https://stackoverflow.com/questions/30209776/docker-container-will-automatically-stop-after-docker-run-d – Andrei Belousov Jul 14 '22 at 19:16

2 Answers2

2

I hope I understand the problem.

When you do docker run torchserve:local ...., by default it runs the CMD which is torchserve --start --model-store model_store --models densenet161=densenet161.mar but since the command runs in the background, your newly created docker container will immediately exit. Due to this same problem, i.e. to prevent docker exit it is possible to add tail -f /dev/null.

Look at the official docker entry point of torchserve https://github.com/pytorch/serve/blob/master/docker/dockerd-entrypoint.sh#L12 They tail it at the end to prevent docker exit

eroot163pi
  • 1,791
  • 1
  • 11
  • 23
0

My suggestion would be to rebuild the image.

Tip: Always give a name to the container you work with --name tag example: docker run --name container_name

Try to access with bash : docker exec -it 4b126bd87f21 bash

ganesh raj
  • 21
  • 1