Files
paddlepaddle--paddle/tools/dockerfile/Dockerfile.ubuntu20
T
2026-07-13 12:40:42 +08:00

201 lines
8.5 KiB
Docker

# A image for building paddle binaries
# Use cuda devel base image for both cpu and gpu environment
# When you modify it, please be aware of cudnn-runtime version
FROM <baseimg>
MAINTAINER PaddlePaddle Authors <paddle-dev@baidu.com>
# ENV variables
ARG WITH_GPU
ARG WITH_AVX
ENV WITH_GPU=${WITH_GPU:-ON}
ENV WITH_AVX=${WITH_AVX:-ON}
ENV DEBIAN_FRONTEND=noninteractive
<setcuda>
ENV HOME /root
# Add bash enhancements
COPY paddle/scripts/docker/root/ /root/
RUN chmod 777 /tmp
RUN apt-key del 7fa2af80
RUN rm /etc/apt/sources.list.d/*
RUN apt-key adv --fetch-keys https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
RUN apt-get update --allow-unauthenticated && \
apt-get install -y software-properties-common && \
apt-get install -y curl wget vim git unzip pigz zstd unrar tar xz-utils libssl-dev bzip2 gzip \
coreutils ntp language-pack-zh-hans libsm6 libxext6 libxrender-dev libgl1-mesa-glx \
bison graphviz libjpeg-dev zlib1g-dev automake locales swig net-tools libtool kmod \
libbz2-dev libexpat1-dev libffi-dev libgdbm-dev liblzma-dev libncursesw5-dev libreadline-dev \
libsqlite3-dev pkg-config tk-dev uuid-dev
<install_cpu_package>
# Downgrade gcc&&g++
WORKDIR /usr/bin
COPY tools/dockerfile/build_scripts /build_scripts
RUN bash /build_scripts/install_trt.sh
# Older versions of patchelf limited the size of the files being processed and were fixed in this pr.
# # https://github.com/NixOS/patchelf/commit/ba2695a8110abbc8cc6baf0eea819922ee5007fa
# # So install a newer version here.
RUN bash /build_scripts/install_patchelf.sh
#RUN apt-get install -y gcc-8 g++-8
RUN bash /build_scripts/install_gcc.sh gcc82
RUN cp gcc gcc.bak && cp g++ g++.bak && rm gcc && rm g++
RUN ln -sf /usr/local/gcc-8.2/bin/gcc /usr/local/bin/gcc
RUN ln -sf /usr/local/gcc-8.2/bin/g++ /usr/local/bin/g++
RUN ln -sf /usr/local/gcc-8.2/bin/gcc /usr/bin/gcc
RUN ln -sf /usr/local/gcc-8.2/bin/g++ /usr/bin/g++
RUN ln -sf /usr/local/gcc-8.2/bin/gcc /usr/bin/cc
ENV PATH=/usr/local/gcc-8.2/bin:$PATH
RUN bash /build_scripts/install_cudnn.sh cudnn841
ENV CUDNN_VERSION=8.4.1
RUN rm -rf /build_script
# install cmake
WORKDIR /home
RUN wget -q https://cmake.org/files/v3.18/cmake-3.18.0-Linux-x86_64.tar.gz && tar -zxvf cmake-3.18.0-Linux-x86_64.tar.gz && rm cmake-3.18.0-Linux-x86_64.tar.gz
ENV PATH=/home/cmake-3.18.0-Linux-x86_64/bin:$PATH
RUN wget -q https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-2.5.1.tar.gz && \
tar -xzf mpdecimal-2.5.1.tar.gz && \
cd mpdecimal-2.5.1 && \
./configure --prefix=/usr/local > /dev/null && \
make -j"$(nproc)" > /dev/null && \
make install > /dev/null && \
cd .. && \
rm -rf mpdecimal-2.5.1 mpdecimal-2.5.1.tar.gz && \
ldconfig
# Build free-threaded 3.13 before normal 3.13 so python3.13 stays non-free-threaded.
RUN set -eux; \
build_python() { \
py_ver="$1"; \
shift; \
wget -q "https://www.python.org/ftp/python/${py_ver}/Python-${py_ver}.tgz"; \
tar -xzf "Python-${py_ver}.tgz"; \
cd "Python-${py_ver}"; \
configure_opts="--prefix=/usr/local --enable-shared --enable-optimizations --with-lto --with-system-expat --with-system-libmpdec --with-ensurepip=install"; \
if ./configure --help | grep -q -- "--with-system-ffi"; then \
configure_opts="${configure_opts} --with-system-ffi"; \
fi; \
CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" CFLAGS="-Wformat" ./configure ${configure_opts} "$@" > /dev/null; \
make -j"$(nproc)" > /dev/null; \
make altinstall > /dev/null; \
cd ..; \
rm -rf "Python-${py_ver}" "Python-${py_ver}.tgz"; \
ldconfig; \
}; \
build_python 3.10.0; \
build_python 3.11.0; \
build_python 3.12.0; \
build_python 3.13.0 --disable-gil --with-mimalloc; \
build_python 3.13.0
ENV LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}
# Keep Ubuntu's /usr/bin/python3 for system scripts such as lsb_release.
RUN ln -sf /usr/local/bin/python3.10 /usr/bin/python
RUN for py in 3.10 3.11 3.12 3.13 3.13t; do \
python${py} -m pip install --no-cache-dir --upgrade pip; \
done && \
python3.10 -m pip install setuptools==69.5.1 && \
python3.11 -m pip install setuptools==69.5.1 && \
python3.12 -m pip install --break-system-packages setuptools==69.5.1 && \
for py in 3.10 3.11 3.12 3.13 3.13t; do \
printf '#!/bin/sh\nexec /usr/local/bin/python%s -m pip "$@"\n' "$py" > "/usr/local/bin/pip${py}" && \
chmod +x "/usr/local/bin/pip${py}"; \
done && \
ln -sf /usr/local/bin/pip3.10 /usr/local/bin/pip && \
ln -sf /usr/local/bin/pip3.10 /usr/local/bin/pip3 && \
python3.13 -m pip install setuptools==69.5.1 && \
python3.13t -m pip install setuptools==69.5.1
RUN wget -q https://ftp.gnu.org/gnu/binutils/binutils-2.33.1.tar.gz && \
tar -xzf binutils-2.33.1.tar.gz && \
cd binutils-2.33.1 && \
./configure && make -j && make install && cd .. && rm -rf binutils-2.33.1 binutils-2.33.1.tar.gz
# Install Go and glide
RUN wget --no-check-certificate -qO- https://paddle-ci.gz.bcebos.com/go1.17.2.linux-amd64.tar.gz | \
tar -xz -C /usr/local && \
mkdir /root/gopath && \
mkdir /root/gopath/bin && \
mkdir /root/gopath/src
ENV GOROOT=/usr/local/go GOPATH=/root/gopath
# should not be in the same line with GOROOT definition, otherwise docker build could not find GOROOT.
ENV PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin
# install glide
RUN apt-get install -y golang-glide
# git credential to skip password typing
RUN git config --global credential.helper store
# Fix locales to en_US.UTF-8
RUN localedef -i en_US -f UTF-8 en_US.UTF-8
RUN pip3.10 --no-cache-dir install ipython==5.3.0 && \
pip3.10 --no-cache-dir install ipykernel==4.6.0 wheel && \
pip3.11 --no-cache-dir install ipython==5.3.0 && \
pip3.11 --no-cache-dir install ipykernel==4.6.0 wheel && \
pip3.12 --no-cache-dir install ipython==5.3.0 && \
pip3.12 --no-cache-dir install ipykernel==4.6.0 wheel && \
python3.13 -m pip --no-cache-dir install ipython==5.3.0 && \
python3.13 -m pip --no-cache-dir install ipykernel==4.6.0 wheel && \
python3.13t -m pip --no-cache-dir install ipython==5.3.0 && \
python3.13t -m pip --no-cache-dir install ipykernel==4.6.0 wheel
# For PaddleTest CE
RUN pip3.10 --no-cache-dir install pytest && \
pip3.11 --no-cache-dir install pytest && \
pip3.12 --no-cache-dir install pytest && \
python3.13 -m pip --no-cache-dir install pytest && \
python3.13t -m pip --no-cache-dir install pytest
RUN pip3.10 --no-cache-dir install pre-commit==2.17.0 && \
pip3.10 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \
pip3.11 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \
pip3.12 --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \
python3.13 -m pip --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0 && \
python3.13t -m pip --no-cache-dir install cpplint==1.6.0 clang-format==13.0.0
COPY ./python/requirements.txt /root/
COPY ./python/unittest_py/requirements.txt /home/
COPY ./paddle/scripts/compile_requirements.txt /home/
# Free-threaded Python 3.13 only installs compile helpers because broader
# requirements currently pull packages without cp313t wheels.
RUN pip3.10 --no-cache-dir install -r /root/requirements.txt && \
pip3.10 --no-cache-dir install -r /home/requirements.txt && \
pip3.10 --no-cache-dir install -r /home/compile_requirements.txt && \
pip3.11 --no-cache-dir install -r /root/requirements.txt && \
pip3.11 --no-cache-dir install -r /home/requirements.txt && \
pip3.11 --no-cache-dir install -r /home/compile_requirements.txt && \
pip3.12 --no-cache-dir install -r /root/requirements.txt && \
pip3.12 --no-cache-dir install -r /home/requirements.txt && \
pip3.12 --no-cache-dir install -r /home/compile_requirements.txt && \
python3.13 -m pip --no-cache-dir install -r /root/requirements.txt && \
python3.13 -m pip --no-cache-dir install -r /home/requirements.txt && \
python3.13 -m pip --no-cache-dir install -r /home/compile_requirements.txt && \
python3.13t -m pip --no-cache-dir install -r /home/compile_requirements.txt
# clang12
RUN apt-get update &&\
apt install -y clang-12
ARG CC=/usr/bin/clang-12
ARG CXX=/usr/bin/clang++-12
# ccache 4.2.0
RUN wget -q https://paddle-ci.gz.bcebos.com/ccache-4.8.2.tar.gz && \
tar xf ccache-4.8.2.tar.gz && mkdir /usr/local/ccache-4.8.2 && cd ccache-4.8.2 && \
mkdir build && cd build && \
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/ccache-4.8.2 .. && \
make -j8 && make install && \
ln -s /usr/local/ccache-4.8.2/bin/ccache /usr/local/bin/ccache && \
cd ../../ && rm -rf ccache-4.8.2.tar.gz
EXPOSE 22