{"id":87201,"date":"2024-01-19T21:47:11","date_gmt":"2024-01-19T13:47:11","guid":{"rendered":"http:\/\/gulass.cn\/?p=87201"},"modified":"2024-01-19T21:47:11","modified_gmt":"2024-01-19T13:47:11","slug":"docker-use-r","status":"publish","type":"post","link":"https:\/\/gulass.cn\/docker-use-r.html","title":{"rendered":"\u4e3a\u4ec0\u4e48\u8981\u5728 Docker \u4e2d\u4f7f\u7528 R\uff1f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nR \u8bed\u8a00\uff0c\u4e00\u79cd\u81ea\u7531\u8f6f\u4ef6\u7f16\u7a0b\u8bed\u8a00\u4e0e\u64cd\u4f5c\u73af\u5883\uff0c\u4e3b\u8981\u7528\u4e8e\u7edf\u8ba1\u5206\u6790\u3001\u7ed8\u56fe\u3001\u6570\u636e\u6316\u6398\u3002R \u5185\u7f6e\u591a\u79cd\u7edf\u8ba1\u5b66\u53ca\u6570\u5b57\u5206\u6790\u529f\u80fd\u3002R \u7684\u53e6\u4e00\u5f3a\u9879\u662f\u7ed8\u56fe\u529f\u80fd\uff0c\u5236\u56fe\u5177\u6709\u5370\u5237\u7684\u7d20\u8d28\uff0c\u4e5f\u53ef\u52a0\u5165\u6570\u5b66\u7b26\u53f7\u3002\u2014\u2014\u5f15\u81ea\u7ef4\u57fa\u767e\u79d1\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

opencpu logo<\/p>\n

\u5df2\u7ecf\u6709\u51e0\u7bc7\u5173\u4e8e\u4e3a\u4ec0\u4e48\u8981\u5728 Docker \u4e2d\u4f7f\u7528 R \u7684\u6587\u7ae0\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5c06\u5c1d\u8bd5\u52a0\u5165\u4e00\u4e2a DevOps \u7684\u89c2\u70b9\uff0c\u5e76\u89e3\u91ca\u5728 OpenCPU \u7cfb\u7edf\u7684\u73af\u5883\u4e2d\u5982\u4f55\u4f7f\u7528\u5bb9\u5668\u5316 R \u6765\u6784\u5efa\u548c\u90e8\u7f72 R \u670d\u52a1\u5668\u3002
\n\u6709\u5728 #rstats \u4e16\u754c\u7684\u4eba\u771f\u6b63\u5730\u5199\u8fc7\u4e3a\u4ec0\u4e48\u4ed6\u4eec\u4f7f\u7528 Docker\uff0c\u800c\u4e0d\u662f\u5982\u4f55\u4e48\uff1f<\/p>\n

\u2014 Jenny Bryan (@JennyBryan)\u00a0September 29, 2017<\/p>\n

1\uff1a\u8f7b\u677e\u5f00\u53d1<\/strong><\/div>\n

OpenCPU \u7cfb\u7edf\u7684\u65d7\u8230\u662f OpenCPU \u670d\u52a1\u5668\uff1a\u5b83\u662f\u4e00\u4e2a\u6210\u719f\u4e14\u5f3a\u5927\u7684 Linux \u6808\uff0c\u7528\u4e8e\u5728\u7cfb\u7edf\u548c\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5d4c\u5165 R\u3002\u56e0\u4e3a OpenCPU \u662f\u5b8c\u5168\u5f00\u6e90\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 DockerHub \u4e0a\u6784\u5efa\u548c\u53d1\u5e03\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u4e00\u4e2a\u53ef\u4ee5\u7acb\u5373\u4f7f\u7528\u7684 OpenCPU \u548c RStudio \u7684 Linux \u670d\u52a1\u5668\uff08\u4f7f\u7528\u7aef\u53e3 8004 \u6216 80\uff09\uff1a<\/p>\n

docker run -t -p 8004:8004 opencpu\/rstudio<\/pre>\n

\u73b0\u5728\u53ea\u9700\u5728\u4f60\u7684\u6d4f\u89c8\u5668\u6253\u5f00 http:\/\/localhost:8004\/ocpu\/ \u548c http:\/\/localhost:8004\/rstudio\/ \u5373\u53ef\uff01\u5728 rstudio \u4e2d\u7528\u7528\u6237 opencpu\uff08\u5bc6\u7801\uff1aopencpu\uff09\u767b\u5f55\u6765\u6784\u5efa\u6216\u5b89\u88c5\u5e94\u7528\u7a0b\u5e8f\u3002\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u81ea\u8ff0\u6587\u4ef6\u3002<\/p>\n

Docker \u8ba9\u5f00\u59cb\u4f7f\u7528 OpenCPU \u53d8\u5f97\u7b80\u5355\u3002\u5bb9\u5668\u7ed9\u4f60\u4e00\u4e2a\u5145\u5206\u7075\u6d3b\u7684 Linux \u673a\u5668\uff0c\u800c\u65e0\u9700\u5728\u7cfb\u7edf\u4e0a\u5b89\u88c5\u4efb\u4f55\u4e1c\u897f\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7 rstudio \u670d\u52a1\u5668\u5b89\u88c5\u8f6f\u4ef6\u5305\u6216\u5e94\u7528\u7a0b\u5e8f\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 docker exec \u8fdb\u5165\u5230\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1\u5668\u7684 root shell \u4e2d\uff1a<\/p>\n

# Lookup the container ID\r\ndocker ps\r\n# Drop a shell\r\ndocker exec -i -t eec1cdae3228 \/bin\/bash<\/pre>\n

\u4f60\u53ef\u4ee5\u5728\u670d\u52a1\u5668\u7684 shell \u4e2d\u5b89\u88c5\u5176\u4ed6\u8f6f\u4ef6\uff0c\u81ea\u5b9a\u4e49 apache2 \u7684 httpd \u914d\u7f6e\uff08auth\uff0c\u4ee3\u7406\u7b49\uff09\uff0c\u8c03\u6574 R \u9009\u9879\uff0c\u901a\u8fc7\u9884\u52a0\u8f7d\u6570\u636e\u6216\u5305\u7b49\u6765\u4f18\u5316\u6027\u80fd\u3002<\/p>\n

2\uff1a \u901a\u8fc7 DockerHub \u53d1\u5e03\u548c\u90e8\u7f72<\/strong><\/div>\n

\u6700\u5f3a\u5927\u7684\u662f\uff0cDocker \u53ef\u4ee5\u901a\u8fc7 DockerHub \u53d1\u5e03\u548c\u90e8\u7f72\u3002\u8981\u521b\u5efa\u4e00\u4e2a\u5b8c\u5168\u72ec\u7acb\u7684\u5e94\u7528\u7a0b\u5e8f\u5bb9\u5668\uff0c\u53ea\u9700\u4f7f\u7528\u6807\u51c6\u7684 opencpu \u955c\u50cf\u5e76\u6dfb\u52a0\u4f60\u7684\u7a0b\u5e8f\u3002<\/p>\n

\u51fa\u4e8e\u672c\u6587\u7684\u76ee\u7684\uff0c\u6211\u901a\u8fc7\u5728\u6bcf\u4e2a\u4ed3\u5e93\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684 \u201cDockerfile\u201d\uff0c\u5c06\u4e00\u4e9b\u793a\u4f8b\u7a0b\u5e8f\u6253\u5305\u4e3a docker \u5bb9\u5668\u3002\u4f8b\u5982\uff1anabel \u7684 Dockerfile \u5305\u542b\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n

FROM opencpu\/base\r\nRUN R -e 'devtools::install_github(\"rwebapps\/nabel\")'<\/pre>\n

\u5b83\u91c7\u7528\u6807\u51c6\u7684 opencpu\/base \u955c\u50cf\uff0c\u5e76\u4ece Github \u4ed3\u5e93\u5b89\u88c5 nabel\u3002\u6700\u7ec8\u5f97\u5230\u4e00\u4e2a\u5b8c\u5168\u9694\u79bb\u3001\u72ec\u7acb\u7684\u7a0b\u5e8f\u3002\u4efb\u4f55\u4eba\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u8fd9\u6837\u7684\u547d\u4ee4\u542f\u52a8\u7a0b\u5e8f\uff1a<\/p>\n

docker run -d 8004:8004 rwebapps\/nabel<\/pre>\n

-d \u4ee3\u8868\u5b88\u62a4\u8fdb\u7a0b\u76d1\u542c 8004 \u7aef\u53e3\u3002\u5f88\u663e\u7136\uff0c\u4f60\u53ef\u4ee5\u8c03\u6574 Dockerfile \u6765\u5b89\u88c5\u4efb\u4f55\u5176\u5b83\u7684\u8f6f\u4ef6\u6216\u8bbe\u7f6e\u4f60\u9700\u8981\u7684\u7a0b\u5e8f\u3002<\/p>\n

\u5bb9\u5668\u5316\u90e8\u7f72\u5c55\u793a\u4e86 Docker \u7684\u771f\u6b63\u80fd\u529b\uff1a\u5b83\u53ef\u4ee5\u53d1\u5e03\u53ef\u4ee5\u5f00\u7bb1\u5373\u7528\u7684\u72ec\u7acb\u8f6f\u4ef6\uff0c\u800c\u65e0\u9700\u5b89\u88c5\u4efb\u4f55\u8f6f\u4ef6\u6216\u4f9d\u8d56\u4ed8\u8d39\u6258\u7ba1\u7684\u670d\u52a1\u3002\u5982\u679c\u4f60\u66f4\u559c\u6b22\u4e13\u4e1a\u7684\u6258\u7ba1\uff0c\u90a3\u4f1a\u6709\u8bb8\u591a\u516c\u53f8\u4e50\u610f\u5728\u53ef\u6269\u5c55\u7684\u57fa\u7840\u8bbe\u65bd\u4e0a\u4e3a\u4f60\u6258\u7ba1 docker \u7a0b\u5e8f\u3002<\/p>\n

3\uff1a \u8de8\u5e73\u53f0\u6784\u5efa<\/strong><\/div>\n

\u8fd8\u6709 Docker \u7528\u4e8e OpenCPU \u7684\u7b2c\u4e09\u79cd\u65b9\u5f0f\u3002\u6bcf\u6b21\u53d1\u5e03\uff0c\u6211\u4eec\u90fd\u6784\u5efa 6 \u4e2a\u64cd\u4f5c\u7cfb\u7edf\u7684 opencpu-server \u5b89\u88c5\u5305\uff0c\u5b83\u4eec\u5728 https:\/\/archive.opencpu.org \u4e0a\u516c\u5e03\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u5df2\u7ecf\u4f7f\u7528 DockerHub \u5b8c\u5168\u81ea\u52a8\u5316\u4e86\u3002\u4ee5\u4e0b\u955c\u50cf\u4ece\u6e90\u4ee3\u7801\u81ea\u52a8\u6784\u5efa\u6240\u6709\u6808\uff1a<\/p>\n