r-使用自定义图像在OpenShift Online上运行闪亮的应用程序



我是OpenShift的新手,目前正在使用OpenShift在线探索其功能。我创建了一个简单的R Shiny应用程序,并创建了以下Dockerfile来在OpenShift中构建自定义映像。

# Base image https://hub.docker.com/u/rocker/
FROM rocker/shiny:latest
# expose port
EXPOSE 3838
# system libraries of general use
## install debian packages
RUN apt-get update -qq && apt-get -y --no-install-recommends install 
libxml2-dev 
libcairo2-dev 
libsqlite3-dev 
libmariadbd-dev 
libpq-dev 
libssh2-1-dev 
unixodbc-dev 
libcurl4-openssl-dev 
libssl-dev
## update system libraries
RUN apt-get update && 
apt-get upgrade -y && 
apt-get clean
# copy necessary files
## app folder
RUN mkdir -p /srv/shiny-server/soker
COPY docker.Rproj /srv/shiny-server/soker
COPY server.R /srv/shiny-server/soker
COPY ui.R /srv/shiny-server/soker
COPY renv.lock /srv/shiny-server/soker
COPY server.R /srv/shiny-server/soker
COPY renv  /srv/shiny-server/soker/renv
# install renv & restore packages
RUN Rscript -e 'install.packages("renv")'
RUN Rscript -e 'renv::consent(provided = TRUE)'
RUN Rscript -e 'renv::restore()'
RUN chown -R shiny /srv/shiny-server/
RUN chown -R shiny /var/lib/shiny-server/
# Run as a non-root user
USER 997
# run app on container start
CMD ["R", "-e", "shiny::runApp( '/srv/shiny-server/soker',host = '0.0.0.0', port = 3838)"]

此DockerFile位于以下服务器的源文件夹中。R和ui。R文件。

服务器.R

server <- function(input, output) {

output$distPlot <- renderPlot({

x    <- faithful$waiting
bins <- seq(min(x), max(x), length.out = input$bins + 1)

hist(x, breaks = bins, col = "#75AADB", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")

})

}

ui.R

library(shiny)
ui <- fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "bins",
label = "Number of bins:",
min = 1,
max = 50,
value = 30)
),
mainPanel(
plotOutput(outputId = "distPlot")
)
)
)

使用OpenShift CLI,我使用以下命令运行了一次试运行。

oc new-app <repository> 
--source-secret <secret> --name newapp --strategy=docker --dry-run -o json

尽管我在Dockerfile中公开了端口3838,但输出并没有显示端口3838。

"spec": {
"containers": [
{
"name": "newapp",
"image": "newapp:latest",
"ports": [
{
"containerPort": 8080,
"protocol": "TCP"
},
{
"containerPort": 8443,
"protocol": "TCP"
}
],
"resources": {}
}
]
}
}
},

我是不是遗漏了什么?如何将端口3838添加为容器的默认端口?我已经使用Docker在本地环境中运行了这个程序,我可以通过键入localhost:3838来访问这个闪亮的应用程序。

为了让OpenShift识别暴露的端口,我相信您需要在Dockerfile 上的LABEL中表达这一点

LABEL io.openshift.expose-services="8080:http"

来源:https://github.com/sclorg/s2i-python-container/blob/master/3.9/Dockerfile.fedora#L33

相关内容

最新更新