2

我一直在使用 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 失败)

泊坞窗构建 -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()"
4

1 回答 1

3

我认为一个问题是,在 Dockerfile 内部,您公开端口 80,但您使用 docker run 在 Docker 容器外部导出端口 3838。你没有说这个端口 80 在你的本地主机上暴露在哪里。
相反,将 Dockerfile 中的端口 80 更改为端口 3838(在 EXPOSE 和 shiny.port 中)

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 3838
CMD R -e "options('shiny.port'=3838,shiny.host='0.0.0.0');experimentdocker::run_app()"

跑。请注意,这些行需要在终端中运行。

docker build -t test .
docker run --rm -p 3838:3838 test

然后,要导航,您可能需要 http://localhost:3838

于 2021-08-11T14:29:36.177 回答