Docker and Plumber issue with port forwarding

Viewed 779

Im trying to expose my plumber server over Docker. I'm getting a log from plumber in RStudio that it's listening on my desired port. And swagger launches and runs fine (the API works ok via swagger in my browser connecting over the exposed port for Rstudio of 8787).

i'm running this command as:

docker run -e PASSWORD=rstudio --rm -it -p 8787:8787 -p 3038:3038 -v "/Users/my_name/Google Drive/r_files":"/home/rstudio/r-docker-tutorial" rocker/verse

if i do:

curl http://localhost:3038

I get 'Empty reply from server'

Likewise if i attempt to hit my endpoint in Postman i get 'Could not get any response'

So it appears that the port isn't being successfully proxied by Docker, but i'm a bit stuck as this doesn't make much sense!

Does anyone have any ideas?

Thanks

Dan

2 Answers

Here is a template Dockerfile we use to expose plumber API :

Dockerfile

FROM rocker/r-ver:4.0.0

WORKDIR /src

RUN apt-get update && apt-get install -y --no-install-recommends \
  git-core \
  libssl-dev \
  libz-dev \
  libcurl4-gnutls-dev \
  libsodium-dev

RUN install2.r --error plumber \
  data.table \
  xgboost 

COPY ./startup.R /var
COPY ./plumber.R /var

EXPOSE 8004
ENTRYPOINT ["R", "-f", "/var/startup.R", "--slave"]

startup.R

library(plumber)
pr <- plumb("plumber.R")
pr$run(host = "0.0.0.0", port = 8004)

plumber.R

#* Health check
#* @get /
#* @serializer unboxedJSON
function() {
    list(status = "OK")
}

I was trying to configure a plumber service in Docker; while plumber replied to the queries made within the container successfully, those queries made from the host would always result in the following error curl: (56) Recv failure: Connection reset by peer.

I followed the code from the following example, part 1 and part 2.

The clue to the solution was provided in Bruno Tremblay's answer:

#startup.R
library(plumber)
pr <- plumb("plumber.R")
pr$run(host = "0.0.0.0", port = 8004)

The use of host="0.0.0.0" is the relevant bit (plumber uses host="127.0.0.1" by default)

Related