运行 Shiny-server 与 3838 端口不同

Run Shiny-server on different port than 3838

我正在容器中部署 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 中最后一行是否有命令行选项?

添加

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 行,如果这是一个问题。)