Change rapidocs IP address for plumber API

A follow-up to my post on deploying a custom model with vetiver. I have successfully implemented @julia 's recommended solution. I am in the process of deploying the API using Docker on a cloud server. I have published it and successfully tested the API's /predict method.

My problem now is trying to make the rapidoc API documentation publicly accessible. I want this available for the site administrator to be able to implement the API. Based on the Docker guide, my Dockerfile ends with

EXPOSE 8000
ENTRYPOINT ["R", "-e", "pr <- plumber::plumb('/opt/ml/plumber.R'); pr$run(host = '0.0.0.0', port = 8000)"]

and I am running the container using the command

docker run -p 8000:8000 -d my-model

This produces the (partial) output:

Running plumber API at http://0.0.0.0:8000
Running rapidoc Docs at http://127.0.0.1:8000/__docs__/

The plumber API is running on 0.0.0.0:8000 which is successfully forwarded to the public IP address. I can correctly query the API and generate valid predictions. However the rapidoc documentation is published to 127.0.0.1 which is not accessible through the public IP address for the cloud server.

My understanding is that I should not expose any applications within the Docker container bound to 127.0.0.1. Instead, I should bind them to 0.0.0.0.

Obviously this is working for the plumber API but is not being applied to rapidoc. Is there any way to configure the documentation to be published to 0.0.0.0?

The rapidoc is served from the same process as the API. It should be served at the rapidoc endpoint. I wonder what is happening here.

Have you taken a look at issues such as this? Or do you need to add swagger = TRUE to pr$run() as described here?

Ok, I think I get it.

All traffic to your API is going through port 8000 on the docker host. Same for the rapidoc page.

If you want to use regular http or https. I suppose you would need to use host port 80 or 443 for https.
Maybe configure a proxy like nginx on the host to redirect traffic to port 8000 if you want to keep using it.

Let me know if that makes sense.

I don't think it is a port issue. It's set to use port 8000 and I have opened that port on the server's firewall. I can successfully use the /predict and /ping methods for the API. It's just the documentation that does not work.

I tested it by adding options(plumber.apiHost="127.0.0.1") to the plumber.R script and this had no effect. I also tried using pr$run(host = '0.0.0.0', port = 8000, swagger = TRUE) in the Dockerfile (I presume this is equivalent to docs = TRUE since swagger is now deprecated), but no change.

When I try to access the documentation at http://XXX.XXX.XXX.XXX:8000/__docs__ (sorry, I can't publish the URL publicly) it returns

{"error":"404 - Resource Not Found"}

This sounds like I am trying to access a method on the API, not the documentation page.

And now I feel completely ridiculous. I was manually typing the URL for the documentation and forgot the trailing backslash. http://XXX.XXX.XXX.XXX:8000/__docs__ does not work, but http://XXX.XXX.XXX.XXX:8000/__docs__/ does.

2 Likes

I also feel ridiculous. We can feel ridiculous together for missing it. The trailing slash strikes again.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.