我正在开发web service的cookie-cutter django
由于某种原因,我必须调用R脚本来响应用户请求。因此,起初,我尝试将R的Dockerfile添加到local.yml中。 (在上一节中)
version: '3'
volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
services:
django: &django
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
image: webservice_local_django
container_name: django
depends_on:
- postgres
- mailhog
volumes:
- .:/app:z
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- "8000:8000"
command: /start
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: webservice_production_postgres
container_name: postgres
volumes:
- local_postgres_data:/var/lib/postgresql/data:Z
- local_postgres_data_backups:/backups:z
env_file:
- ./.envs/.local/.postgres
docs:
image: webservice_local_docs
container_name: docs
build:
context: .
dockerfile: ./compose/local/docs/Dockerfile
env_file:
- ./.envs/.local/.django
volumes:
- ./docs:/docs:z
- ./config:/app/config:z
- ./webservice:/app/webservice:z
ports:
- "7000:7000"
mailhog:
image: mailhog/mailhog:v1.0.0
container_name: mailhog
ports:
- "8025:8025"
redis:
image: redis:5.0
container_name: redis
celeryworker:
<<: *django
image: webservice_local_celeryworker
container_name: celeryworker
depends_on:
- redis
- postgres
- mailhog
ports: []
command: /start-celeryworker
celerybeat:
<<: *django
image: webservice_local_celerybeat
container_name: celerybeat
depends_on:
- redis
- postgres
- mailhog
ports: []
command: /start-celerybeat
flower:
<<: *django
image: webservice_local_flower
container_name: flower
ports:
- "5555:5555"
command: /start-flower
R:
image: r_local
container_name: r_local
build:
context: .
dockerfile: ./compose/local/R/Dockerfile
这是./compose/local/R/Dockerfile
FROM r-base
WORKDIR /app
ADD . /app
RUN Rscript -e 'install.packages("dplyr")'
RUN Rscript -e 'install.packages("xgboost")'
RUN Rscript -e 'install.packages("TSrepr")'
RUN Rscript -e 'install.packages("ggplot2")'
RUN Rscript -e 'install.packages("foreach")'
RUN Rscript -e 'install.packages("doParallel")'
但是当我运行docker-compose -f local.yml up
时
发生了一些错误
r_local | Fatal error: you must specify '--save', '--no-save' or '--vanilla'
r_local exited with code 2
我用Google搜索它,发现了一些discussion 但是它提到了Rserve。我不认为我用过它。 因此,我尝试了另一种将R直接安装在django容器中的方法。
sudo docker-compose -f local.yml run --rm django apt-get update
sudo docker-compose -f local.yml run --rm django apt install r-base-core -y
sudo docker-compose -f local.yml run --rm django apt-get install r-cran-quantre\
g
sudo docker-compose -f local.yml run --rm django apt-get install r-cran-sparsem
sudo docker-compose -f local.yml run --rm django Rscript -e 'install.packages("\
dplyr")'
sudo docker-compose -f local.yml run --rm django Rscript -e 'install.packages("\
xgboost")'
sudo docker-compose -f local.yml run --rm django Rscript -e 'install.packages("\
TSrepr")'
sudo docker-compose -f local.yml run --rm django Rscript -e 'install.packages("\
ggplot2")'
sudo docker-compose -f local.yml run --rm django Rscript -e 'install.packages("\
foreach")'
sudo docker-compose -f local.yml run --rm django Rscript -e 'install.packages("\
doParallel")'
然后,我得到了
E: Unable to locate package r-base-core
E: Unable to locate package r-cran-quantreg
E: Unable to locate package r-cran-sparsem
/entrypoint: line 45: exec: Rscript: not found
/entrypoint: line 45: exec: Rscript: not found
...
(为清晰起见,省略了许多行)
在django docker环境中是否有任何简单的方法来调用Rscript?非常感谢。