FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #253 from Kaggle/pip_install_fix · HadokenCode/docker-python@8707bef · GitHub

Commit 8707bef

Browse files
d1jang
authored
Merge pull request Kaggle#253 from Kaggle/pip_install_fix
Add ENTRYPOINT script to initialize the image.
2 parents 4d4487e + a66bcee commit 8707bef

3 files changed

Lines changed: 40 additions & 17 deletions

File tree

‎Dockerfile‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,15 @@ ADD patches/sitecustomize.py /root/.local/lib/python3.6/site-packages/sitecustom
523523
# Set backend for matplotlib
524524
ENV MPLBACKEND "agg"
525525

526-
# Set up pip to enable pip install.
527-
ADD patches/kaggle_bashrc /root
528-
# Patch the system-wide bashrc file for non-root users.
529-
RUN cat /root/kaggle_bashrc >> /etc/bash.bashrc
530-
RUN rm /root/kaggle_bashrc
526+
# Set up an initialization script to be executed before any other commands initiated by the user.
527+
ADD patches/entrypoint.sh /root/entrypoint.sh
528+
RUN chmod +x /root/entrypoint.sh
529+
# NOTE: ENTRYPOINT set by "FROM <image>" should preceed the our own custom entrypoint.
530+
# Currently tini is set as ENTRYPOINT for the base image, and it can be combined with our entrypoint (https://github.com/krallin/tini).
531+
# ENTRYPOINT gets executed by "docker run <image> <command>" and it runs <command> at the end of its execution.
532+
# Make sure tini exists.
533+
RUN /usr/bin/tini -h > /dev/null
534+
ENTRYPOINT ["/usr/bin/tini", "--", "/root/entrypoint.sh"]
531535

532536
# Finally, apply any locally defined patches.
533537
RUN /bin/bash -c \

‎kaggle_tools_update.Dockerfile‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ FROM gcr.io/kaggle-images/python:latest
1818

1919
RUN pip install --upgrade git+https://github.com/Kaggle/learntools
2020

21-
# Set up pip to enable pip install.
22-
ADD patches/kaggle_bashrc /root
23-
# Patch the system-wide bashrc file for non-root users.
24-
RUN cat /root/kaggle_bashrc >> /etc/bash.bashrc
25-
RUN rm /root/kaggle_bashrc
21+
# TODO(dsjang): Remove these lines once the docker image build turns green since they are copied from Dockerfile
22+
# to apply on top of the last green.
23+
# Set up an initialization script to be executed before any other commands initiated by the user.
24+
ADD patches/entrypoint.sh /root/entrypoint.sh
25+
RUN chmod +x /root/entrypoint.sh
26+
# NOTE: ENTRYPOINT set by "FROM <image>" should preceed the our own custom entrypoint.
27+
# Currently tini is set as ENTRYPOINT for the base image, and it can be combined with our entrypoint (https://github.com/krallin/tini).
28+
# ENTRYPOINT gets executed by "docker run <image> <command>" and it runs <command> at the end of its execution.
29+
# Make sure tini exists.
30+
RUN /usr/bin/tini -h > /dev/null
31+
ENTRYPOINT ["/usr/bin/tini", "--", "/root/entrypoint.sh"]
Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# This shell script is executed as an entrypoint file for the Kernels docker image.
4+
# It sets up the execution environment before starting the Jypyter Notebook Server.
5+
# Refer to https://docs.docker.com/engine/reference/builder/#entrypoint for details.
16

2-
# Kaggle-specific .bashrc script to be appended to /etc/bash.bashrc to apply it
3-
# when any user session starts.
47
# This script sets up pip to enable a user to install and use python modules via
58
# pip intall. $KAGGLE_WORKING_DIR should be available for it to work.
6-
79
if [[ ! -z "${KAGGLE_WORKING_DIR}" ]]; then
810
PIP_INSTALL_PREFIX_DIR="${KAGGLE_WORKING_DIR}/pip"
11+
PIP_INSTALLED_MODULE_DIR="${PIP_INSTALL_PREFIX_DIR}/pip_installed"
912
PIP_CONFIG_FILE_PATH="${KAGGLE_WORKING_DIR}/config/pip/pip.conf"
1013

1114
# Create a directory for pip to install modules.
@@ -15,17 +18,27 @@ if [[ ! -z "${KAGGLE_WORKING_DIR}" ]]; then
1518
# installation. Also, ignore-installed is set to true to prevent pip
1619
# from trying to remove existing modules from the read-only filesystem.
1720
mkdir -p `dirname ${PIP_CONFIG_FILE_PATH}`
18-
echo "[install]\nprefix=${PIP_INSTALL_PREFIX_DIR}\nignore-installed=true" > ${PIP_CONFIG_FILE_PATH}
21+
echo -e "[install]\nprefix=${PIP_INSTALL_PREFIX_DIR}\nignore-installed=true" > ${PIP_CONFIG_FILE_PATH}
1922
# Instruct pip to use this config file.
2023
export PIP_CONFIG_FILE=${PIP_CONFIG_FILE_PATH}
2124

2225
# Set up PYTHONPATH correctly to include the user-installed library.
2326
# Note that the pip prefix directory overrides the system default to enable
2427
# a user to use his/her installed one.
2528
# TODO(dsjang): Currently "lib/python3.6/site-packages" is hard-coded
26-
# throughout Dockerfile. Parameterize it to avoid a version mismatch.
27-
export PYTHONPATH=${PIP_INSTALL_PREFIX_DIR}/lib/python3.6/site-packages:${PYTHONPATH}
29+
# throughout Dockerfile. Parameterize it to avoid a version mismatch.
30+
# TODO(dsjang): This is a hack to sidestep a problem of Python ignoring modules
31+
# in .../site-packages other than the system-wide and user-specific site packages.
32+
mkdir -p "${PIP_INSTALL_PREFIX_DIR}/lib/python3.6/site-packages"
33+
ln -s "${PIP_INSTALL_PREFIX_DIR}/lib/python3.6/site-packages" ${PIP_INSTALLED_MODULE_DIR}
34+
export PYTHONPATH=${PIP_INSTALLED_MODULE_DIR}:${PYTHONPATH}
35+
36+
# Create a symbolic link to site-packages.
37+
# can't override conda installed package.
2838

2939
# Include pip-installed binaries in PATH.
3040
export PATH=${PATH}:${PIP_INSTALL_PREFIX_DIR}/bin
31-
fi
41+
fi
42+
43+
# Execute the command provided from "docker run" in the current process.
44+
exec "$@"

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL