Skip to content
Advertisement

Docker run does not produce any endpoint

I am trying to dockerize this repo. After building it like so:

docker build -t layoutlm-v2 .

I try to run it like so:

docker run -d -p 5001:5000 layoutlm-v2

It downloads the necessary libraries and packages:

enter image description here

And then nothing… No errors, no endpoints generated, just radio silence.

What’s wrong? And how do I fix it?

Advertisement

Answer

You appear to be expecting your application to offer a service on port 5000, but it doesn’t appear as if that’s how your code behaves.

Looking at your code, you seem to be launching a service using gradio. According the quickstart, calling gr.Interface(...).launch() will launch a service on localhost:7860, and indeed, if you inspect a container booted from your image, we see:

root@74cf8b2463ab:/app# ss -tln
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     Process
LISTEN      0           2048                 127.0.0.1:7860                0.0.0.0:*

There’s no way to access a service listening on localhost from outside the container, so we need to figure out how to fix that.

Looking at these docs, it looks like you can control the listen address using the server_name parameter:

server_name

to make app accessible on local network, set this to “0.0.0.0”. Can be set by environment variable GRADIO_SERVER_NAME. If None, will use “127.0.0.1”.

So if we run your image like this:

docker run -p 7860:7860 -e GRADIO_SERVER_NAME=0.0.0.0 layoutlm-v2

Then we should be able to access the interface on the host at http://localhost:7860/…and indeed, that seems to work:

enter image description here


Unrelated to your question:

  • You’re setting up a virtual environment in your Dockerfile, but you’re not using it, primarily because of a typo here:

    ENV PATH="VIRTUAL_ENV/bin:$PATH"
    

    You’re missing a $ on $VIRTUAL_ENV.

  • You could optimize the order of operations in your Dockerfile. Right now, making a simple change to your Dockerfile (e.g, editing the CMD setting) will cause much of your image to be rebuilt. You could avoid that by restructuring the Dockerfile like this:

    FROM python:3.9
    
    # Install dependencies
    RUN apt-get update && apt-get install -y tesseract-ocr
    
    RUN pip install virtualenv && virtualenv venv -p python3
    ENV VIRTUAL_ENV=/venv
    ENV PATH="$VIRTUAL_ENV/bin:$PATH"
    
    WORKDIR /app
    COPY requirements.txt ./
    RUN pip install -r requirements.txt
    
    RUN git clone https://github.com/facebookresearch/detectron2.git
    RUN python -m pip install -e detectron2
    
    COPY . /app
    
    # Run the application:
    CMD ["python", "-u", "app.py"]
    
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement