首页 > 解决方案 > 在不同于 3838 的端口上运行 Shiny-server

问题描述

我正在容器中部署 Shiny-server。默认情况下,Shiny-server 侦听端口 3838,这是来自 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;

我想将此端口更改为 80。我显然可以启动容器实例,登录到它并更改它,但我想在 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"] 

Dockerfile 中的最后一行是否有命令行选项?

标签: rdockerdockerfileshiny-server

解决方案


添加

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

所以也许最终得到:

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"]

(我知道如果不压缩多层可能效率低下,如果您想将该sed行与上一个RUN命令组合起来,则交给您。如果这是一个问题,您可能想要组合更多这些RUN行。)


推荐阅读