r - 构建 Docker 映像并指定端口后,闪亮的应用程序未显示
问题描述
我目前正在尝试构建一个大型 Docker 映像并从中运行一个闪亮的应用程序,以便最终将其部署到 Unix 服务器。镜像构建成功;但是,当我运行映像时,应用程序会运行并完全忽略指定的端口。
更奇怪的是,我首先构建了一个小型测试应用程序,并且这篇 SO 帖子中的说明(Shiny app docker container not loading in browser)起作用了。我将在测试应用程序中使用的相同样式复制到另一个 Shiny 应用程序中,但现在它无法正常工作。
我的 Docker 映像的结构与 ShinyProxy 在其 Github 页面上使用的结构类似:https ://github.com/openanalytics/shinyproxy-template :
|-- Dockerfile
|-- Rprofile.site
|-- app_stuff
|-- app.R
|-- accessory files called from app.R...
我的Dockerfile如下:
# Install R version 3.5.1
FROM r-base:3.5.1
# system libraries of general use - I don't know if these are right ????
RUN apt-get update && apt-get install -y \
default-jdk \
libbz2-dev \
zlib1g-dev \
gfortran \
liblzma-dev \
libpcre3-dev \
libreadline-dev \
xorg-dev \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libssh2-1-dev \
libxml2-dev
RUN R -e "install.packages('remotes');"
RUN R -e "library(remotes); \
remotes::install_version('shiny', version='1.1.0', repos='https://cran.r-project.org/'); \
remotes::install_version('tidyverse', version='1.2.1', repos='https://cran.r-project.org/'); \
remotes::install_version('ggiraph', version='0.6.0', repos='https://cran.r-project.org/'); \
remotes::install_version('plotly', version='4.8.0', repos='https://cran.r-project.org/'); \
remotes::install_version('CausalImpact', version='1.2.3', repos='https://cran.r-project.org/'); \
remotes::install_version('reshape2', version='1.4.3', repos='https://cran.r-project.org/'); \
remotes::install_version('bsts', version='0.8.0', repos='https://cran.r-project.org/'); \
remotes::install_version('xts', version='0.10-2', repos='https://cran.r-project.org/'); \
remotes::install_version('BoomSpikeSlab', version='1.0.0', repos='https://cran.r-project.org/'); \
remotes::install_version('Boom', version='0.8', repos='https://cran.r-project.org/'); \
remotes::install_version('MASS', version='7.3-50', repos='https://cran.r-project.org/'); \
remotes::install_version('dygraphs', version='1.1.1.4', repos='https://cran.r-project.org/'); \
remotes::install_version('prophet', version='0.4', repos='https://cran.r-project.org/'); \
remotes::install_version('rlang', version='0.3.3', repos='https://cran.r-project.org/'); \
remotes::install_version('Rcpp', version='1.0.1', repos='https://cran.r-project.org/'); \
remotes::install_version('zoo', version='1.8-1', repos='https://cran.r-project.org/'); \
remotes::install_version('RJDBC', version='0.2-7.1', repos='https://cran.r-project.org/'); \
remotes::install_version('rJava', version='0.9-10', repos='https://cran.r-project.org/'); \
remotes::install_version('shinyjs', version='1.0', repos='https://cran.r-project.org/'); \
remotes::install_version('DT', version='0.5', repos='https://cran.r-project.org/'); \
remotes::install_version('shinyBS', version='0.61', repos='https://cran.r-project.org/');"
# copy the app to the image
RUN mkdir /root/app_stuff
COPY app_stuff /root/app_stuff
COPY Rprofile.site /usr/lib/R/etc/
EXPOSE 3838
CMD ["R", "-e", "shiny::runApp('/root/app_stuff')"]
我的Rprofile.site是:
local({
options(shiny.port = 3838, shiny.host = "0.0.0.0")
})
使用命令构建文件后
docker build -t price_opt .
然后运行图像
docker run -it -p 3838:3838 price_opt
我希望看到闪亮的应用程序打印出:Listening on http://0.0.0.0:3838
,但它打印出:
Listening on http://127.0.0.1:6688
我在本地机器上找不到。
同样,最奇怪的是这种设置适用于较小的闪亮应用程序。当我在docker run
较小的应用程序上从上面运行该命令时,该应用程序在 localhost:3838 下可用。
关于为什么会发生这种情况的任何想法?我的最后一件事是,Shiny Proxy 网站上的这个用户似乎有类似的问题 ( https://support.openanalytics.eu/t/shiny-app-listening-on-wrong-host/957 )。他的问题是某种拼写错误,但它的行为似乎与 Shiny 应用程序完全忽略 Rprofile.site 和docker run
命令中提供的端口号的方式相同。
编辑 - 解决方案
感谢用户@Wil,通过将 Dockerfile 的最后一行更改为CMD ["R", "-e", "shiny::runApp('/root/app_stuff', host='0.0.0.0', port=3838)"]
,应用程序能够在 localhost:3838 上正常启动。
解决方案
端口 3838 是 Shiny Server 的默认端口,但会runApp()
选择一个可用端口。看来 R 没有接听你的Rprofile.site
,所以我只想在你的调用中指定端口runApp()
:
CMD ["R", "-e", "shiny::runApp('/root/app_stuff',options = list(port = '3838'))"]
推荐阅读
- pytorch - PyTorch 中两个概率分布的 Jensen-Shanon Divergence
- scala - 在 Spark DataFrame 中查找重叠数据的函数
- matlab - 由凸包创建的曲面上点的值的插值
- git - 错误变基后如何恢复代码版本?
- r - 是否可以将迷你图与 gt 一起使用?
- lua - 使用“FindFirstChild”和“WaitForChild”获得 NIL
- r - 在 R 中使用 string_detect 检测到 data.frame 列中的模式太慢
- asp.net-core - 在 ASP.NET Core 中返回 odata 4 错误
- python - 旧版本的代码出现在 docker 容器中
- discord - 嵌入命令 Discord