Docker Multistage сборка образа
FROM ubuntu:14.04
MAINTAINER Someone
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y software-properties-common &&
rm -rf /var/lib/apt/lists/*
RUN add-apt-repository ppa:fkrull/deadsnakes # python3.5
RUN apt-get update && apt-get install -y \
wget \
ca-certificates \
apparmor \
aufs-tools \
automake \
cmake \
bash-completion \
build-essential \
dpkg-sig \
git \
iptables \
libapparmor-dev \
libcap-dev \
libsqlite3-dev \
mercurial \
parallel \
python-mock \
python-pip \
python-websocket \
mesa-utils \
libgl1-mesa-dev libx11-dev libxt-dev \
libeigen3-dev libflann1.8 libflann-dev libboost-all-dev libqhull*
libgtest-dev freeglut3-dev \
libcurl4-openssl-dev libarchive-dev libwxgtk2.8-* libwxgtk3.0-* ccache \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
RUN sudo update-alternatives --install /usr/bin/clang clang
/usr/bin/clang-3.6 100
RUN sudo update-alternatives --install /usr/bin/clang++ clang++
/usr/bin/clang++-3.6 100
# install Tcl
WORKDIR /tmp
RUN wget http://prdownloads.sourceforge.net/tcl/tcl8.6.6-src.tar.gz \
&& tar -zxvf tcl8.6.6-src.tar.gz \
&& cd tcl8.6.6/unix && ./configure && make -j$(nproc) && sudo make
install \
&& rm /tmp/tcl8.6.6-src.tar.gz
# install Tk
WORKDIR /tmp
RUN wget http://prdownloads.sourceforge.net/tcl/tk8.6.6-src.tar.gz \
&& tar -zxvf tk8.6.6-src.tar.gz \
&& cd tk8.6.6/unix && ./configure && make -j$(nproc) && sudo make
install \
&& rm /tmp/tk8.6.6-src.tar.gz
# install vtk 7 for python3
WORKDIR /tmp
RUN wget http://www.vtk.org/files/release/7.0/VTK-7.0.0.tar.gz \
&& tar -zxvf VTK-7.0.0.tar.gz \
&& mkdir /vtk-build2 \
&& cd /vtk-build2 \
&& cmake \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DBUILD_TESTING:BOOL=OFF \
-DVTK_WRAP_PYTHON:BOOL=ON \
-DVTK_WRAP_PYTHON_SIP:BOOL=ON \
-DVTK_WRAP_TCL:BOOL=ON \
-DVTK_PYTHON_VERSION:STRING=3.5 \
-DVTK_USE_TK:BOOL=ON \
/tmp/VTK-7.0.0 \
&& make -j$(nproc) \
&& cd Wrapping/Python && make -j$(nproc) && sudo make install \
&& rm /tmp/VTK-7.0.0.tar.gz
ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/lib:/vtk-build2/lib
# ---- end of vtk installation process
# install 1.8 pcl from source
WORKDIR /tmp
RUN git clone --depth=1 --branch=roofkit
https://github.com/pbrazdil/pcl.git \
&& mkdir pcl/build \
&& cd /tmp/pcl/build \
&& cmake -DCMAKE_BUILD_TYPE=Release .. \
&& make -j$(nproc) \
&& sudo make -j$(nproc) install
# Install Python 3.5
RUN apt-get update && apt-get install -y --force-yes python3.5
python3.5-dev python3-pip python3.5-tk+ && rm -rf /var/lib/apt/lists/*
RUN python3.5 -m pip install --upgrade pip
# Install Swift
WORKDIR /swift
RUN wget -nv https://swift.org/builds/swift-4.1.2-
release/ubuntu1404/swift-4.1.2-RELEASE/swift-4.1.2-RELEASE-
ubuntu14.04.tar.gz \
&& tar xzf swift-4.1.2-RELEASE-ubuntu14.04.tar.gz && rm swift-4.1.2-
RELEASE-ubuntu14.04.tar.gz
ENV PATH /swift/swift-4.1.2-RELEASE-ubuntu14.04/usr/bin:$PATH
# Install unzip for unzipping Weather files
RUN apt-get update && apt-get install unzip && rm -rf
/var/lib/apt/lists/*
У меня есть этот Dockerfile. Когда я создаю этот Dockerfile, требуется сделать изображение огромного размера. Я хочу уменьшить размер этого файла Dockerfile. Поэтому я добавляю два этапа:- для Python и Swift. Есть ли у вас какие-либо предложения, чтобы сделать это лучше. Большое спасибо за уделенное время.
# Install Python 3.6
FROM python:3.6 AS base
WORKDIR /tmp
FROM base AS dependencies
RUN pip install -r requirements.txt
FROM dependencies AS build
WORKDIR /tmp
COPY . /app
FROM python:3.6-alpine3.7 AS release
WORKDIR /tmp
COPY --from=dependencies /app/requirements.txt ./
COPY --from=dependencies /root/.cache /root/.cache
RUN pip install -r requirements.txt
COPY --from=build /tmp/ ./
# Install Swift
FROM swift:latest as build-swift
RUN mkdir -p /build/lib && cp -R /usr/lib/swift/linux/*.so /build/lib
FROM ubuntu:14.04
COPY --from=build-swift /build/lib/* /usr/lib/
RUN apt-get -q update && \
apt-get -q install -y --no-install-recommends \
libatomic1 \
libbsd0 \
libcurl3 \
libicu55 \
libxml2 \
&& rm -r /var/lib/apt/lists/*
ENV PATH /swift/build-swift/usr/bin:$PATH
Вышеупомянутый раздел для python и быстрого процесса сборки multitage.