如何解决使用Docker托管R plumber API
我正在Windows笔记本电脑上工作,并希望使用Windows的Docker桌面托管我在R(使用水管工包装)中制作的我的API。
在here中找到的教程提供了一个使用以下命令运行预安装的管道工代码的示例:function exactMatch(a,b) {
a = a.split(' ');
b = b.split(' ');
let s = [];
let out = [];
let x = a.map(x => b.includes(x) ? x : null);
x.forEach((v) => {
if (v == null) {
out.push(s);
s = [];
} else {
s.push(v);
}
});
out.push(s);
out = out.map(x => x.join(' ')).filter(x => x);
return out;
}
let a = "your majesty they are ready";
let b = "your highness they are ready";
let c = exactMatch(a,b);
console.log(c);
a = "your majesty they are ready,but this is another test";
b = "your highness they are ready,yet this is another test";
c = exactMatch(a,b);
console.log(c);
a = "hello your majesty they are ready,but this is another test";
b = "hi your highness they are ready,but this is another test made";
b = "hi your highness they are ready,yet this is another test completed";
c = exactMatch(a,b);
console.log(c);
。这将承载给定位置中存在的API:“ C:\ Users \ sidmh \ Documents \ R \ win-library \ 4.0 \ plumber \ examples \ 04-mean-sum \ plumber.R”
但是,我想在以下位置托管一个API:“ C:\ Users \ sidmh \ Documents \ Nutri \ plumber.R”
我该怎么办?
解决方法
您将需要适应plumber
文档中的Dockerfile
,以将自定义my_plumber_api.R
脚本连同以下内容一起存储在“ app”文件夹中:
Dockerfile
FROM rstudio/plumber
# list all the needed packages here in the same fashion
RUN R -e "install.packages('broom')"
# to launch your docker container
CMD ["/app/my_plumber_api.R"]
然后,您需要构建(并为方便起见标记)Docker镜像,然后才能使用以下命令运行:
$ cd projet_folder
$ docker build -t my_plumber_api .
$ docker run -p 8000:8000 my_plumber_api
您应该查看Docker文档以了解具体信息(选择裸露的端口,...)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。