首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python和R最小化docker镜像

使用python和R最小化docker镜像
EN

Stack Overflow用户
提问于 2020-07-04 00:16:50
回答 2查看 737关注 0票数 1

我有以下Dockerfile:

代码语言:javascript
复制
FROM ubuntu:latest

RUN apt-get update \
  && apt-get install -y python3-pip python3-dev \
  && cd /usr/local/bin \
  && ln -s /usr/bin/python3 python \
  && pip3 install --upgrade pip

# Setup the Python's configs
RUN pip install --upgrade pip && \
    pip install --no-cache-dir matplotlib==3.0.2 pandas==0.23.4 numpy==1.16.3 && \
    pip install --no-cache-dir pybase64 && \
    pip install --no-cache-dir scipy && \
    pip install --no-cache-dir dask[complete] && \
    pip install --no-cache-dir dash==1.6.1 dash-core-components==1.5.1 dash-bootstrap-components==0.7.1 dash-html-components==1.0.2 dash-table==4.5.1 dash-daq==0.2.2 && \
    pip install --no-cache-dir plotly && \
    pip install --no-cache-dir adjustText && \
    pip install --no-cache-dir networkx && \
    pip install --no-cache-dir scikit-learn && \
    pip install --no-cache-dir tzlocal

# Setup the R configs
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
RUN add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
RUN apt update
ENV DEBIAN_FRONTEND=noninteractive 
RUN apt install -y r-base
RUN pip install rpy2==2.9.4
RUN apt-get -y install libxml2 libxml2-dev libcurl4-gnutls-dev libssl-dev
RUN echo "r <- getOption('repos'); r['CRAN'] <- 'https://cran.r-project.org'; options(repos = r);" > ~/.Rprofile
RUN Rscript -e "install.packages('BiocManager')"
RUN Rscript -e "BiocManager::install('ggplot2')"
RUN Rscript -e "BiocManager::install('DESeq2')"
RUN Rscript -e "BiocManager::install('RColorBrewer')"
RUN Rscript -e "BiocManager::install('ggrepel')"
RUN Rscript -e "BiocManager::install('factoextra')"
RUN Rscript -e "BiocManager::install('FactoMineR')"
RUN Rscript -e "BiocManager::install('apeglm')"

WORKDIR /
# Copy all the necessary files of the app to the container
COPY ./ ./

# Install the slider-input component
WORKDIR /slider_input
RUN pip install --no-cache-dir slider_input-0.0.1.tar.gz

WORKDIR /
EXPOSE 8050

# Launch the app
CMD ["python", "./app.py"]

它用于运行使用R命令的dash应用程序,并且运行良好。问题在于图像的大小。我想尽可能地最小化图像的大小,但由于python和R的组合,我尝试的所有操作都失败了。

您是否知道如何最小化此图像,并提供相同的功能?

EN

回答 2

Stack Overflow用户

发布于 2020-07-04 00:30:06

使用docker-slim最小化和保护docker图像。docker-slim将分析您的docker镜像,并丢弃您不需要的内容。

它已经被用于Node.js,Python,Ruby,Java,Golang,Rust,Elixir和PHP (一些应用程序类型),运行在Ubuntu,Debian,CentOS,阿尔卑斯甚至Distroless上。

docker-slim已经为生产做好了准备,但请考虑在将容器部署到生产环境之前对其进行测试。缩小对接图像高达30倍,同时使它也安全!

票数 0
EN

Stack Overflow用户

发布于 2020-07-04 01:07:17

多阶段构建将允许您省略编译器工具链、头文件等。从最终图像中,只包含结果代码。

Python的三部分教程具体从这里开始:https://pythonspeed.com/articles/smaller-python-docker-images/

和通用Docker文档:https://docs.docker.com/develop/develop-images/multistage-build/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62719227

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档