Skip to content

Commit 46fd36f

Browse files
committed
Optimize Docker image build
1 parent a1ef367 commit 46fd36f

2 files changed

Lines changed: 21 additions & 27 deletions

File tree

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
slides/
3+
.DS_Store
4+
__pycache__/

Dockerfile

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,42 @@
11
# Use the jupyter/minimal-notebook as the base image
22
FROM quay.io/jupyter/minimal-notebook:latest
33

4-
# Set a shortcut to the tutorial name
4+
# Set environment variables for the tutorial and repository
55
ENV BASENAME="python-tutorial"
6-
ENV REPO="https://github.com/edoardob90/${BASENAME}"
7-
8-
# Set the working directory to the home directory of the notebook user
9-
WORKDIR ${HOME}
10-
11-
# Clone the tutorial repository
12-
RUN git clone \
13-
--branch main \
14-
--depth 1 \
15-
${REPO}
16-
17-
# Set the working directory to the repository directory
18-
WORKDIR ${BASENAME}
6+
ENV REPO=${HOME}/${BASENAME}
7+
ENV IPYTHONDIR="${HOME}/.ipython"
198

20-
# Switch to root user to install additional dependencies (if needed)
9+
# Switch to root user to install additional dependencies
2110
USER root
22-
23-
# Install additional dependencies
2411
RUN apt-get update && \
2512
apt-get install -y --no-install-recommends \
2613
build-essential \
2714
gcc \
2815
g++ \
29-
libffi-dev \
30-
&& \
16+
libffi-dev && \
3117
apt-get clean && \
3218
rm -rf /var/lib/apt/lists/*
3319

3420
# Switch back to the default notebook user
3521
USER ${NB_UID}
3622

37-
# Create the Conda environment defined in environment.yml
38-
# COPY --chown=${NB_USER}:${NB_GID} docker/environment.yml docker/environment.yml
39-
RUN mamba env update -n base -f docker/environment.yml && \
23+
# Set up the Conda environment
24+
COPY docker/environment.yml /tmp/environment.yml
25+
RUN mamba env update -n base -f /tmp/environment.yml && \
4026
mamba clean --all -f -y && \
4127
fix-permissions "${CONDA_DIR}" && \
4228
fix-permissions "/home/${NB_USER}"
4329

44-
# Copy the IPython configuration file (binder/postBuild script)
45-
RUN mkdir -p ${HOME}/.ipython/profile_default && \
46-
cp -a binder/ipython_config.py ${HOME}/.ipython/profile_default/
30+
# Prepare IPython configuration (move earlier in the build)
31+
RUN mkdir -p ${HOME}/.ipython/profile_default
32+
COPY --chown=${NB_UID}:${NB_GID} binder/ipython_config.py ${HOME}/.ipython/profile_default/
4733

48-
# Set the environment variable IPYTHONDIR
49-
ENV IPYTHONDIR="${HOME}/.ipython"
34+
# Copy the repository late in the build process
35+
RUN mkdir -p ${REPO}
36+
COPY --chown=${NB_UID}:${NB_GID} . ${REPO}/
37+
38+
# Set the working directory to the repository
39+
WORKDIR ${REPO}
5040

5141
# Use the default ENTRYPOINT from the base image to start Jupyter Lab
5242
ENTRYPOINT ["tini", "-g", "--", "start.sh"]

0 commit comments

Comments
 (0)