【问题标题】:MLflow Rstudio Dockerfile Permission deniedMLflow Rstudio Dockerfile 权限被拒绝
【发布时间】:2021-10-10 09:19:20
【问题描述】:

目标

在远程 MLflow 跟踪服务器中跟踪 R 模型(在 kubernetes 中运行)。该模型是在本地计算机上从 RStudio 开发的,在 Docker 容器中运行。

设置

根据我的研究,我需要创建安装了 conda 的 RStudio 映像。之后我想运行 MLflow 文档中的示例。

Dockerfile

FROM rocker/rstudio

USER root

ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
ENV MLFLOW_BIN=/root/miniconda3/bin/mlflow
ENV MLFLOW_PYTHON_BIN=/root/miniconda3/bin/python

RUN apt-get update

RUN apt-get install -y wget && rm -rf /var/lib/apt/lists/*

RUN wget \
    https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
    && mkdir /root/.conda \
    && bash Miniconda3-latest-Linux-x86_64.sh -b \
    && rm -f Miniconda3-latest-Linux-x86_64.sh 
RUN conda --version

RUN R -e 'install.packages("mlflow")'
RUN R -e 'install.packages("glmnet")'
RUN R -e 'install.packages("carrier")'

RUN pip install -U mlflow==1.19.0

train.R(调整后的示例来自 here)

# The data set used in this example is from http://archive.ics.uci.edu/ml/datasets/Wine+Quality
# P. Cortez, A. Cerdeira, F. Almeida, T. Matos and J. Reis.
# Modeling wine preferences by data mining from physicochemical properties. In Decision Support Systems, Elsevier, 47(4):547-553, 2009.

library(mlflow)
library(glmnet)
library(carrier)

set.seed(40)

# Read the wine-quality csv file
data <- read.csv("wine-quality.csv")

# Split the data into training and test sets. (0.75, 0.25) split.
sampled <- sample(1:nrow(data), 0.75 * nrow(data))
train <- data[sampled, ]
test <- data[-sampled, ]

# The predicted column is "quality" which is a scalar from [3, 9]
train_x <- as.matrix(train[, !(names(train) == "quality")])
test_x <- as.matrix(test[, !(names(train) == "quality")])
train_y <- train[, "quality"]
test_y <- test[, "quality"]

alpha <- mlflow_param("alpha", 0.5, "numeric")
lambda <- mlflow_param("lambda", 0.5, "numeric")

Sys.setenv(MLFLOW_S3_ENDPOINT_URL="<EP>")
Sys.setenv(AWS_ACCESS_KEY_ID="<some_key>")
Sys.setenv(AWS_SECRET_ACCESS_KEY="<some_secret>")

mlflow_set_experiment("Wine R experiment")
mlflow_set_tracking_uri("<http...blabla>")

with(mlflow_start_run(), {
    model <- glmnet(train_x, train_y, alpha = alpha, lambda = lambda, family= "gaussian", standardize = FALSE)
    predictor <- crate(~ glmnet::predict.glmnet(!!model, as.matrix(.x)), !!model)
    predicted <- predictor(test_x)

    rmse <- sqrt(mean((predicted - test_y) ^ 2))
    mae <- mean(abs(predicted - test_y))
    r2 <- as.numeric(cor(predicted, test_y) ^ 2)

    message("Elasticnet model (alpha=", alpha, ", lambda=", lambda, "):")
    message("  RMSE: ", rmse)
    message("  MAE: ", mae)
    message("  R2: ", r2)

    mlflow_log_param("alpha", alpha)
    mlflow_log_param("lambda", lambda)
    mlflow_log_metric("rmse", rmse)
    mlflow_log_metric("r2", r2)
    mlflow_log_metric("mae", mae)

    mlflow_log_model(predictor, "model")
})

它的 POC 不介意不安全的环境变量。

我这样运行容器:

docker run --rm -p 8787:8787 -e PASSWORD=password --mount type=bind,source=$(pwd)/mlflow/examples/r_wine,target=/home/rstudio rstudio-mlflow

问题

每次从 RStudio 运行文件时,最后一行(mlflow_log_model(predictor, "model"))都会出错:

cannot start processx process '/root/miniconda3/bin/mlflow' (system error 13, Permission denied) @unix/processx.c:608 (processx_exec)

从 RStudio 终端列出 conda bin 文件夹时,我的权限被拒绝。您能帮我如何正确安装带有 RStudio 映像的 conda。

【问题讨论】:

  • 我有点困惑 Conda 在这里的用途。如果要使用pip 安装所有东西,为什么不直接安装本机 Python?至于权限,Rocker下的RStudio以rstudio用户运行,没有提升权限,但Conda是root安装的。调整权限或安装为您计划运行的用户。 The Rocker docs 显示您可以在docker run 中使用-e ROOT=TRUE 向用户添加root 权限。
  • 如果我正确理解了 mlflow 文档,它需要 conda env 来运行与 trackong 服务器的 coomucation(或者只是推荐)。我尝试了 env Root 但同样的问题。我可以在 docker -ti bash 之后将其作为 Rscrip train.r 运行,但不能从 RStudio 运行

标签: r docker rstudio conda mlflow


【解决方案1】:

Rstudio 是使用本地用户 rstudio 安装的。 Dockerfile 是here。 rstudio 用户没有 /root/ 文件夹的权限。这就是为什么您在尝试从 rstudio 执行 mlflow 时出现“权限被拒绝”错误的原因。

以下 Dockerfile 工作正常。

FROM rocker/rstudio

RUN useradd -g rstudio -m conda
USER conda

WORKDIR /home/conda

ENV PATH="/home/conda/miniconda3/bin:${PATH}"
ARG PATH="/home/conda/miniconda3/bin:${PATH}"
ENV MLFLOW_BIN=/home/conda/miniconda3/bin/mlflow
ENV MLFLOW_PYTHON_BIN=/home/conda/miniconda3/bin/python

RUN wget \
    https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
    && bash Miniconda3-latest-Linux-x86_64.sh -b \
    && rm -f Miniconda3-latest-Linux-x86_64.sh
RUN conda --version

USER root

RUN R -e 'install.packages("mlflow")'
RUN R -e 'install.packages("glmnet")'
RUN R -e 'install.packages("carrier")'

RUN pip install -U mlflow==1.19.0

【讨论】:

    猜你喜欢
    • 2021-12-20
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    • 2021-03-07
    • 1970-01-01
    • 2015-08-30
    相关资源
    最近更新 更多