Skip to content

Commit 33a0e56

Browse files
behacklchopan050
andauthored
enhancement: optimize Docker image build and runtime footprint (#4604)
* docker: add libgl1 runtime dependency for OpenGL * docker: tighten .dockerignore for smaller build context * docs(docker): add runtime notes for latest image * docs(docker): note ctex is not included by default --------- Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
1 parent 80fd11e commit 33a0e56

4 files changed

Lines changed: 88 additions & 25 deletions

File tree

.dockerignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
11
.git
2+
3+
# Development / test artifacts
4+
__pycache__
5+
**/__pycache__
6+
*.pyc
7+
*.pyo
8+
*.pyd
9+
*.egg-info
10+
dist/
11+
build/
12+
coverage.xml
13+
14+
# Not needed to install the package
15+
docs/
16+
tests/
17+
example_scenes/
18+
media/
19+
logo/
20+
scripts/

docker/Dockerfile

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,74 @@
1-
FROM python:3.11-slim
1+
# ── Stage 1: builder ─────────────────────────────────────────────────────────
2+
FROM python:3.14-slim AS builder
23

34
RUN apt-get update -qq \
45
&& apt-get install --no-install-recommends -y \
56
build-essential \
67
gcc \
78
cmake \
9+
make \
10+
pkg-config \
11+
wget \
812
libcairo2-dev \
913
libffi-dev \
1014
libpango1.0-dev \
11-
freeglut3-dev \
12-
ffmpeg \
13-
pkg-config \
14-
make \
15-
wget \
16-
ghostscript \
17-
fonts-noto
15+
libegl-dev \
16+
&& rm -rf /var/lib/apt/lists/*
1817

19-
RUN fc-cache -fv
20-
21-
# setup a minimal texlive installation
18+
# Setup a minimal TeX Live installation (no ctex: drops ~100 MB of CJK fonts/packages)
2219
COPY docker/texlive-profile.txt /tmp/
2320
ENV PATH=/usr/local/texlive/bin/armhf-linux:/usr/local/texlive/bin/aarch64-linux:/usr/local/texlive/bin/x86_64-linux:$PATH
24-
RUN wget -O /tmp/install-tl-unx.tar.gz http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz && \
25-
mkdir /tmp/install-tl && \
26-
tar -xzf /tmp/install-tl-unx.tar.gz -C /tmp/install-tl --strip-components=1 && \
27-
/tmp/install-tl/install-tl --profile=/tmp/texlive-profile.txt \
21+
RUN wget -O /tmp/install-tl-unx.tar.gz http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz \
22+
&& mkdir /tmp/install-tl \
23+
&& tar -xzf /tmp/install-tl-unx.tar.gz -C /tmp/install-tl --strip-components=1 \
24+
&& /tmp/install-tl/install-tl --profile=/tmp/texlive-profile.txt \
2825
&& tlmgr install \
29-
amsmath babel-english cbfonts-fd cm-super count1to ctex doublestroke dvisvgm everysel \
26+
amsmath babel-english cbfonts-fd cm-super count1to doublestroke dvisvgm everysel \
3027
fontspec frcursive fundus-calligra gnu-freefont jknapltx latex-bin \
3128
mathastext microtype multitoc physics prelim2e preview ragged2e relsize rsfs \
32-
setspace standalone tipa wasy wasysym xcolor xetex xkeyval
29+
setspace standalone tipa wasy wasysym xcolor xetex xkeyval \
30+
&& rm -rf /tmp/install-tl /tmp/install-tl-unx.tar.gz
31+
32+
# Install manim into an isolated virtualenv
33+
ENV VIRTUAL_ENV=/opt/venv
34+
RUN python -m venv $VIRTUAL_ENV
35+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
3336

34-
# clone and build manim
3537
COPY . /opt/manim
3638
WORKDIR /opt/manim
37-
RUN pip install --no-cache .[jupyterlab]
39+
RUN pip install --no-cache-dir .[jupyterlab]
40+
41+
# ── Stage 2: runtime ─────────────────────────────────────────────────────────
42+
FROM python:3.14-slim
43+
44+
# Runtime libs only:
45+
# - no ffmpeg: PyAV (av package) bundles its own ffmpeg libraries in av.libs/
46+
# - OpenGL: keep EGL for headless rendering and libGL as required by moderngl/glcontext
47+
# - fonts-noto-core instead of fonts-noto (drops CJK noto fonts)
48+
RUN apt-get update -qq \
49+
&& apt-get install --no-install-recommends -y \
50+
libcairo2 \
51+
libpango-1.0-0 \
52+
libpangocairo-1.0-0 \
53+
libpangoft2-1.0-0 \
54+
libffi8 \
55+
libegl1 \
56+
libgl1 \
57+
ghostscript \
58+
fonts-noto-core \
59+
fontconfig \
60+
&& rm -rf /var/lib/apt/lists/*
61+
62+
RUN fc-cache -fv
63+
64+
# Copy TeX Live from builder
65+
ENV PATH=/usr/local/texlive/bin/armhf-linux:/usr/local/texlive/bin/aarch64-linux:/usr/local/texlive/bin/x86_64-linux:$PATH
66+
COPY --from=builder /usr/local/texlive /usr/local/texlive
3867

39-
RUN pip install -r docs/requirements.txt
68+
# Copy the pre-built virtualenv from builder
69+
ENV VIRTUAL_ENV=/opt/venv
70+
COPY --from=builder /opt/venv /opt/venv
71+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
4072

4173
ARG NB_USER=manimuser
4274
ARG NB_UID=1000
@@ -49,11 +81,8 @@ RUN adduser --disabled-password \
4981
--uid ${NB_UID} \
5082
${NB_USER}
5183

52-
# create working directory for user to mount local directory into
5384
WORKDIR ${HOME}
54-
USER root
55-
RUN chown -R ${NB_USER}:${NB_USER} ${HOME}
56-
RUN chmod 777 ${HOME}
85+
RUN chown -R ${NB_USER}:${NB_USER} ${HOME} && chmod 777 ${HOME}
5786
USER ${NB_USER}
5887

59-
CMD [ "/bin/bash" ]
88+
CMD ["/bin/bash"]

docker/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ Multi-platform builds are possible by running
1313
docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag manimcommunity/manim:TAG -f docker/Dockerfile .
1414
```
1515
from the root directory of the repository.
16+
17+
# Runtime notes
18+
- The image is built via a multi-stage Dockerfile (build dependencies are not
19+
carried into the runtime stage).
20+
- The image does not include the `ffmpeg` CLI binary.
21+
- The default TeX installation is minimal and does not include `ctex`.
22+
- Headless OpenGL rendering relies on EGL/GL runtime libraries available in the
23+
image.

docs/source/installation/docker.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ For our image ``manimcommunity/manim``, there are the following tags:
1818
``-p`` (preview file) and ``-f`` (show output file in the file browser)
1919
are not supported.
2020

21+
.. note::
22+
23+
The Docker image ships with a minimal TeX Live installation. In particular,
24+
``ctex`` is not installed by default. If your scenes rely on
25+
``TexTemplateLibrary.ctex``, install it in the container via
26+
``tlmgr install ctex``.
27+
2128

2229
Basic usage of the Docker container
2330
-----------------------------------

0 commit comments

Comments
 (0)