Skip to content

Instantly share code, notes, and snippets.

@matthewfeickert
Last active October 17, 2019 21:12
Show Gist options
  • Save matthewfeickert/9007c41145356897a7173b6d0b9e74f0 to your computer and use it in GitHub Desktop.
Save matthewfeickert/9007c41145356897a7173b6d0b9e74f0 to your computer and use it in GitHub Desktop.
A quickly thrown together Dockerfile to get Python 3.8 and Jupyter together

The image

This is a Docker image that has a user (docker) with sudo powers and a Python 3.8 runtime with NumPy and Jupyter installed inside. Jupyter has had a configuration file generated and edited to set some helpful defaults.

Building

The image can be built with the provided Makefile

Running

docker run --rm -it -p 8888:8888 python38jupyter:latest
FROM python:3.8
MAINTAINER Matthew Feickert <[email protected]>
USER root
WORKDIR /root
SHELL [ "/bin/bash", "-c" ]
RUN apt-get -qq -y update && \
apt-get -qq -y upgrade && \
apt-get -qq -y install \
wget \
curl \
git \
make \
sudo \
bash-completion && \
apt-get -y autoclean && \
apt-get -y autoremove && \
rm -rf /var/lib/apt-get/lists/*
RUN pip install --upgrade --no-cache-dir pip setuptools wheel && \
pip install --no-cache-dir numpy jupyter
# Enable tab completion by uncommenting it from /etc/bash.bashrc
# The relevant lines are those below the phrase "enable bash completion in interactive shells"
RUN export SED_RANGE="$(($(sed -n '\|enable bash completion in interactive shells|=' /etc/bash.bashrc)+1)),$(($(sed -n '\|enable bash completion in interactive shells|=' /etc/bash.bashrc)+7))" && \
sed -i -e "${SED_RANGE}"' s/^#//' /etc/bash.bashrc && \
unset SED_RANGE
# Create user "docker" with sudo powers
RUN useradd -m docker && \
usermod -aG sudo docker && \
echo '%sudo ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers && \
cp /root/.bashrc /home/docker/ && \
mkdir /home/docker/data && \
chown -R --from=root docker /home/docker
# Use C.UTF-8 locale to avoid issues with ASCII encoding
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV HOME /home/docker
# Have Jupyter notebooks launch without additional command line options
RUN jupyter notebook --generate-config && \
sed -i -e "/allow_root/ a c.NotebookApp.allow_root = True" ${HOME}/.jupyter/jupyter_notebook_config.py && \
sed -i -e "/custom_display_url/ a c.NotebookApp.custom_display_url = \'http://localhost:8888\'" ${HOME}/.jupyter/jupyter_notebook_config.py && \
sed -i -e "/c.NotebookApp.ip/ a c.NotebookApp.ip = '0.0.0.0'" ${HOME}/.jupyter/jupyter_notebook_config.py && \
sed -i -e "/open_browser/ a c.NotebookApp.open_browser = False" ${HOME}/.jupyter/jupyter_notebook_config.py
RUN chown -R --from=root docker ${HOME}
WORKDIR /home/docker/data
ENV USER docker
USER docker
ENV PATH /home/docker/.local/bin:$PATH
CMD [ "/bin/bash" ]
default: image
image:
docker build -f Dockerfile \
-t python38jupyter:latest \
--compress .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment