yum的Docker多阶段构建

时间:2018-12-27 06:19:03

标签: docker centos dockerfile yum docker-multi-stage-build

我正在尝试从centos构建多阶段docker镜像

FROM centos as python-base

RUN yum install -y wget \
tar \
make \
gcc \
gcc-c++ \
zlib \
zlib-devel \
libffi-devel \
openssl-devel \
&& yum clean all

WORKDIR /usr/src/

RUN wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

RUN tar xzf Python-3.7.0.tgz

WORKDIR /usr/src/Python-3.7.0

RUN ./configure --enable-optimizations

RUN make altinstall

RUN python3.7 -V

#=====================================================================================

FROM centos:cs as python37

COPY --from=python-base /usr/local/lib/python3.7 /usr/local/lib/python3.7
COPY --from=python-base /usr/local/bin/pip3.7 /usr/local/bin/pip3.7
COPY --from=python-base /usr/local/bin/python3.7 /usr/local/bin/python3.7

RUN ln -s /usr/local/bin/pip3.7 /usr/local/bin/pip
RUN ln -s /usr/local/bin/python3.7 /usr/local/bin/python

如上所示,我已经从python-base阶段构建了python37。在这里,我已将所需的工件从python-base复制到python37阶段。

FROM centos as httpd-base

RUN yum -y groupinstall "Development tools"\
httpd-2.4.6-88.el7.centos.x86_64 \
&& yum clean all

所以我的问题是,从httpd-base阶段复制什么构件才能构建具有httpd的映像,而不是仅在安装过程中需要的所有开发工具。

在这方面的任何最佳做法也值得赞赏。 提前致谢。

0 个答案:

没有答案