4

I am deploying Shiny-server in container. By default Shiny-server listens on port 3838, here is piece from shiny-server.conf

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Define a server that listens on port 3838
server {
  listen 3838;

I would like to change this port to 80. I obviously can launch container instance, login to it, and change it, but I would like to change it in Dockerfile.

FROM rocker/shiny:3.5.1

RUN apt-get update && apt-get install libcurl4-openssl-dev libv8-3.14-dev -y &&\
  mkdir -p /var/lib/shiny-server/bookmarks/shiny

# Download and install library
RUN R -e "install.packages(c('shinydashboard', 'shinyjs', 'V8'))"

# copy the app to the image COPY shinyapps /srv/shiny-server/
COPY "reports" "/srv/shiny-server/sample-apps/reports/"

# make all app files readable (solves issue when dev in Windows, but building in Ubuntu)
RUN chmod -R 755 /srv/shiny-server/

EXPOSE 80
CMD ["/usr/bin/shiny-server.sh"] 

Is there command line option for final line in Dockerfile?

user1700890
  • 7,144
  • 18
  • 87
  • 183
  • 1
    `RUN sed -i -e 's/\blisten 3838\b/listen 80/g' /path/to/shiny-server.conf`? – r2evans Feb 26 '21 at 20:42
  • 1
    Alternatively, I like to keep mine at 3838, and when I run it, the port is mapped externally, as in `docker --ports "80:3838" ...` (or whatever the cli args are). – r2evans Feb 26 '21 at 20:43
  • @r2evans, thank you, I am planning to deploy it on Azure. Azure docker implementation does not port mapping afaik. – user1700890 Feb 26 '21 at 20:45
  • 1
    @r2evans, you first comment worked, you can posted as the solution and I will accept. I tried to create copy of shiny-server.conf file and edit it and then copy, but it got overwritten somehow – user1700890 Feb 26 '21 at 20:50

1 Answers1

1

Add

RUN sed -i -e 's/\blisten 3838\b/listen 80/g' /path/to/shiny-server.conf

So perhaps ending up with:

FROM rocker/shiny:3.5.1

RUN apt-get update && apt-get install libcurl4-openssl-dev libv8-3.14-dev -y &&\
  mkdir -p /var/lib/shiny-server/bookmarks/shiny

# Download and install library
RUN R -e "install.packages(c('shinydashboard', 'shinyjs', 'V8'))"

# copy the app to the image COPY shinyapps /srv/shiny-server/
COPY "reports" "/srv/shiny-server/sample-apps/reports/"

# make all app files readable (solves issue when dev in Windows, but building in Ubuntu)
RUN chmod -R 755 /srv/shiny-server/

RUN sed -i -e 's/\blisten 3838\b/listen 80/g' /path/to/shiny-server.conf

EXPOSE 80
CMD ["/usr/bin/shiny-server.sh"]

(I know multiple layers can be inefficient if not compacted, over to you if you want to combine the sed line with the previous RUN command. You might want to combine more of those RUN lines, if that's a concern.)

r2evans
  • 141,215
  • 6
  • 77
  • 149