Get IP address for docker session of RStudio

Trying to use RStudio within docker.

The github guide to rocker says that you can use RStudio in a browser after you build the docker container for RStudio via

sudo docker run -d -p 8787:8787 -e PASSWORD=<password> --name rstudio rocker/rstudio

This creates a container, but the recommended method of retrieving the url (i.e., Docker Toolbox) is deprecated.

I have tried using this method from Stack to get the URL but no RStudio session appeared when I entered the output in the form of http://172.17.0.3:8787 in my browser.

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
1 Like

The correct url was http://localhost:8787/

1 Like

Well done figuring that out!

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

As an additional tidbit here, the -p 8787:8787 is responsible for this. It says "map my local port 8787 to port 8787 on the container". For instance, if you used -p 8888:8787, then you would access the browser at http://localhost:8888 :grinning_face_with_smiling_eyes:

Also, docker inspect container_name is a handy way to get lots of information about the container :grinning_face_with_smiling_eyes: The IP doesn't help a bunch in this case because often the docker network is a different one than your browser is using (of course, that is all configurable, but is complicated).

In any case, suffice it to say that -p someport:serviceport is your friend when you need to access a service running in docker locally! :grinning_face_with_smiling_eyes:

1 Like

If you are interested in developing a R project inside RStudio server in a Docker container, maybe package {devindocker} can interest you. This allows to launch a Docker for a specific project and you can manage libraries installation persistently using {renv}.

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.