【发布时间】:2021-10-15 00:08:53
【问题描述】:
我一直在使用 Golem 框架来构建 R Shiny 应用程序,这非常有用,但我在框架的 docker 文件创建方面遇到了困难。
工作流程:
在 RStudio 中,我创建了一个新的 golem 包,并插入了 MIT 许可证(没有许可证我在 devtools::check() 中收到警告)
Run devtools::check() # Check pass no error no warnings
运行 golem::add_dockerfile() # 在项目根目录中创建一个 Dockerfile
关闭 RStudio 并在 VScode 中打开文件夹(docker build 通过 RStudio 失败)
docker build -t 测试。
docker run --rm -p 3838:3838 测试
我现在看到以下控制台输出
R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> options('shiny.port'=80,shiny.host='0.0.0.0');experimentdocker::run_app()
Loading required package: shiny
Listening on http://0.0.0.0:80
但是当我导航到 http://0.0.0.0:80 时,我看到“此页面现在无法正常工作”
我非常感谢能提供的任何支持。
我在下面包含了标准 golem dockerfile。
FROM rocker/r-ver:4.1.0
RUN apt-get update && apt-get install -y git-core libcurl4-openssl-dev libgit2-dev libicu-dev libssl-dev libxml2-dev make pandoc pandoc-citeproc && rm -rf /var/lib/apt/lists/*
RUN echo "options(repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl', Ncpus = 4)" >> /usr/local/lib/R/etc/Rprofile.site
RUN R -e 'install.packages("remotes")'
RUN Rscript -e 'remotes::install_version("shiny",upgrade="never", version = "1.6.0")'
RUN Rscript -e 'remotes::install_version("config",upgrade="never", version = "0.3.1")'
RUN Rscript -e 'remotes::install_version("golem",upgrade="never", version = "0.3.1")'
RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
RUN R -e 'remotes::install_local(upgrade="never")'
RUN rm -rf /build_zone
EXPOSE 80
CMD R -e "options('shiny.port'=80,shiny.host='0.0.0.0');experimentdocker::run_app()"
【问题讨论】:
-
我认为一个问题是,在 Dockerfile 内部,您公开了 80 端口,但您使用 docker run 在 Docker 容器外部导出了 3838 端口。你没有说这个端口 80 在你的本地主机上暴露在哪里。相反,将 Dockerfile 中的端口 80 更改为端口 3838(在 EXPOSE 和 shiny.port 中)然后导航,您可能需要localhost:3838
-
天哪,非常感谢!这解决了我的问题。
-
我将此添加为答案,以便您将其标记为已解决。
-
或者将 -p 3838:3838 替换为 -p 80:80