Set up Apache webserver in Docker container with rstudio to host html generated Rmd analysis

I have a Centos VM that I use to host Rstudio community edition. On this VM I have both hosted Shiny apps as well as several ad hoc analysis in Rmd html format.

Whenever I create a new Rmd analysis, I would just run rmarkdown::render_site() and then move the contents of the newly created _site directory to /var/www/html/project_name. I can then navigate to '/project_name' and view the analysis in my browser. Since this VM is behind a firewall it's safe and I regularly share analysis with stakeholders in Rmd html format (It is hard to convey quite how much I love Rstudio).

For my current project, I am trying to set things up locally with Docker. I am using running Rocker/verse image as a container and have created a project within it that has generated some html in the _site folder.

I tried to install Apache from within the container, actually from within the rstudio instance within the container by using the terminal tab. I tried following this tutorial.

sudo apt update
sudo apt install apcache2

That's as far as I got. In the tutorial it says next step is to 'adjust firewall' with sudo ufw app list. When I run that I get command not found.

I tried visiting localhost/my_project but the page is not found.

After doing some searching I confused myself. I could not tell if I should try to get the apache server working within my container or instead use a separate docker image for apache?

How can I set up my docker container with rstudio inside to be able to host html markdown pages?

I realize that the commercial software does not work for everyone, but this is one of the primary use cases that RStudio Connect was designed to simplify. It can do the scheduling of the re-renders and send out customized emails to stakeholders when the content updates. If you haven't taken a look, I definitely recommend it! We even have a docker container that can be used for a free trial for 45 days (just reach out to sales@rstudio.com for a trial license): https://github.com/rstudio/rstudio-docker-products

In any case, I think what you're running into is docker problems. The rocker images expose the 3838 and 8787 ports by default and start the according services in your container for you. Just installing apache is not enough - you also need to start the service (i.e. run apache directly, because containers may not have an init system) and expose the port that it is listening on in order to access the files in your browser. (You won't have to do the firewall bit inside of a container. Containers presume the firewall will sit outside :smile:)

It is possible to do this in a single container, but it might be preferable to "volume mount" your output directory from your host into the rocker container, and "volume mount" the same directory into an apache container, so that the files can be served by a separate process / container. Lots of ways to accomplish the same task :smiley:

2 Likes

Thank you for the suggestions. Good to know that rsconnect has that functionality.
Meantime, it sounds like a separate apache container is the way to go. I will explore that route.

1 Like

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