繁体   English   中英

R Docker:无法通过socket连接到本地MySQL服务器

[英]R Docker: Can't connect to local MySQL server through socket

我已经使用了一个 golem 管道到 package & dockerize 我的应用程序。

对于初学者,我正在尝试使用 docker 在 windows pc 上本地部署应用程序(也尝试在 linux 上运行它,但遇到同样的问题)。 该应用程序从本地 SQlite 数据库中收集数据,该数据库也在我的电脑上运行(一旦部署在服务器上就会类似)。

当我将应用程序作为 package 运行时,应用程序功能正常。 但是,一旦我创建了 docker 图像并运行它,应用程序启动但无法连接到我的本地 sql 数据库,返回此错误:无法通过套接字连接到本地 MySQL/dmysql.sock ' ' (2 "没有这样的文件或目录")

与应用程序内部数据库的连接如下所示:

    con =  dbConnect(RMariaDB::MariaDB(), dbname = "training_dash_db", user = "root", password = "", host = '127.0.0.1')

我的 docker 文件如下所示:

FROM rocker/tidyverse:3.5.3
RUN R -e 'install.packages("remotes")'
RUN R -e 'remotes::install_github("r-lib/remotes", ref = "97bbf81")'
RUN R -e 'remotes::install_cran("shiny")'
RUN R -e 'remotes::install_github("Thinkr-open/golem")'
RUN R -e 'remotes::install_cran("processx")'
RUN R -e 'remotes::install_cran("attempt")'
RUN R -e 'remotes::install_cran("DT")'
RUN R -e 'remotes::install_cran("glue")'
RUN R -e 'remotes::install_cran("htmltools")'
RUN R -e 'remotes::install_cran("shinydashboard")'
RUN R -e 'remotes::install_cran("shinydashboardPlus")'
RUN R -e 'remotes::install_cran("lubridate")'
RUN R -e 'remotes::install_cran("dplyr")'
RUN R -e 'remotes::install_cran("purrr")'
RUN R -e 'remotes::install_cran("plotly")'
RUN R -e 'remotes::install_cran("DBI")'
RUN R -e 'remotes::install_cran("tibbletime")'
RUN R -e 'remotes::install_cran("tsibble")'
RUN R -e 'remotes::install_cran("shinyWidgets")'
RUN R -e 'remotes::install_cran("leaflet")'
RUN R -e 'remotes::install_cran("pool")'
RUN R -e 'remotes::install_cran("RMariaDB")'
RUN R -e 'remotes::install_cran("roxygen2")'
COPY K2dashboard_*.tar.gz /app.tar.gz
RUN R -e 'remotes::install_local("/app.tar.gz")'
EXPOSE 80
EXPOSE 3306
CMD R -e "options('shiny.port'=80,shiny.host='0.0.0.0');K2dashboard::run_app()"

谢谢。

以下是我可以看到的问题:

  • 您使用 127.0.0.1 作为数据库的主机。 一旦进入容器,此地址指的是容器的内部 IP ,而不是来自您的主机/另一个容器的地址。 因此您的应用无法访问主机数据库。

  • 您尚未在容器内安装 MariaDB 的驱动程序

以下是解决方案:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM