I would like to embed the TPOT autoML library in a Docker container from rocker/r-ver:4.1.0. To make dream come true, I used the R package reticulate. I was inspired by this project to build the Dockerfile. However, it doesn't work in R environment.
In my opinion, some debian dependencies are missing. I added libstdc++6 or gcc but it doesn't work too. Anybody have an idea? Many thanks.
main.R
X_train <- iris[,-5]
y_train <- iris$Species
tpot <- reticulate::import("tpot")
tp <- tpot$TPOTClassifier(generations = 1)
fit <- tp$fit(X_train, y_train)
score <- fit$predict(X_train)
print(score)
Dockerfile
FROM rocker/r-ver:4.1.0
RUN R -q -e 'install.packages("remotes")'
RUN R -q -e 'remotes::install_github("rstudio/reticulate", upgrade = "never")'
RUN R -q -e 'reticulate::install_miniconda()'
RUN R -q -e 'reticulate::conda_install("r-reticulate", c("python=3.8.13", "numpy<1.24"))'
RUN R -q -e 'reticulate::conda_install("r-reticulate", "tpot", pip = TRUE)'
COPY main.R main.R
CMD ["Rscript", "main.R"]
Build and Run the Docker image:
sudo docker build --no-cache -t tpot-demo .
sudo docker run tpot-demo
This Dockerfile works for me. You?
I don't know what change did the trick. Perhaps using the
rocker/tidyverseimage so thatdevtoolsgets installed?I've always set a
WORKDIRand I notice you didn't. Perhaps that?A general piece of advice is that
docker execis a great tool for debugging Dockerfiles. You can start from a base image (i.e.rocker/tidyverse),docker execinto it, test commands one by one until you can get the whole sequence to work, and then code this sequence to the Dockerfile.Here is the output: