From a2dba4d52b3ea577ff81e228a6763cc8184a8d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gilles?= <sebastien.gilles@inria.fr> Date: Tue, 4 May 2021 19:09:15 +0200 Subject: [PATCH] Rewrite partly the Dockerfile so that: - The image is derived from continuumio/miniconda3 rather than Ubuntu (maybe it is not the right call - no clue one way or another, but we probably have shave off a bit of space. The miniconda one is apparently base on Debian). - The project is no longer cloned from gitlab, but is rather read from the host (the command line is therefore a bit longer and is documented in the README). The reason for doing so is that the image is lighter and fork may build their own image from their actual master branch rather than silently taking the one from the main project. I have also removed several lines that seems to add nothing; maybe I was wrong on some of these calls. The terminal where the `run` command is run is no longer silent; I don't know what triggered the difference here. --- README.md | 2 +- docker/Dockerfile | 62 ++++++++++------------------------------------- 2 files changed, 14 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index a6ecad0..6190592 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ __NOTE__: It is possible to use the notebooks directly from some IDEs like [VSCo It is possible to execute the notebooks from a Docker machine by simply: ``` -docker run -p 8888:8888 registry.gitlab.inria.fr/formations/cpp/gettingstartedwithmoderncpp:latest +docker run -v $PWD:/home/formation/gettingstartedwithmoderncpp -p 8888:8888 registry.gitlab.inria.fr/formations/cpp/gettingstartedwithmoderncpp:latest ``` The simply in your browser just simply go to [http://localhost:8888/](http://localhost:8888/). diff --git a/docker/Dockerfile b/docker/Dockerfile index 22f6e6c..89f3102 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,58 +1,22 @@ -# Each instruction in this file generates a new layer that gets pushed to your local image cache +# Inspired from https://pythonspeed.com/articles/activate-conda-dockerfile +FROM continuumio/miniconda3 -# Lines preceeded by # are regarded as comments and ignored +LABEL maintainer Vicente Mataix Ferrandiz "vicente.mataix-ferrandiz@inria.fr" and Sébastien Gilles "sebastien.gilles@inria.fr" -# The line below states we will base our new image on the Latest Official Ubuntu -FROM ubuntu:latest - -# Identify the maintainer of an image -LABEL maintainer="vicente.mataix-ferrandiz@inria.fr" - -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get -y clean -RUN apt-get -y update -RUN apt-get -y upgrade -RUN apt-get install -y \ - nano \ - bash \ - wget \ - curl \ - git \ - cmake \ - clang \ - build-essential && \ - apt-get autoremove -y -RUN apt-get -y clean - -# Creation of a "non-root" user +# Create non root user and give him the ownership of /opt/conda. ENV USER "formation" RUN useradd --create-home ${USER} +RUN chown ${USER}:${USER} /opt/conda USER ${USER} -# Default working directory is -WORKDIR /home/${USER} -RUN curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -RUN bash Miniconda3-latest-Linux-x86_64.sh -b -RUN rm -rf Miniconda3-latest-Linux-x86_64.sh - -# Changing to home -WORKDIR /home/${USER} -RUN git clone https://gitlab.inria.fr/formations/cpp/gettingstartedwithmoderncpp.git +# Create the environment: +WORKDIR /home/${USER}/gettingstartedwithmoderncpp +COPY environment.yml . +RUN conda env create -f environment.yml -# Change the default shell to be bash +# Make RUN commands use the new environment: SHELL ["/bin/bash", "-c"] -# Conda environment -WORKDIR /home/${USER}/gettingstartedwithmoderncpp -# RUN echo ". /home/${USER}/miniconda3/etc/profile.d/conda.sh" >> ~/.bashrc -RUN /home/${USER}/miniconda3/bin/conda env create -f environment.yml -RUN /home/${USER}/miniconda3/bin/conda init bash -# RUN source ~/.bashrc -RUN source /home/${USER}/miniconda3/etc/profile.d/conda.sh -RUN /home/${USER}/miniconda3/bin/conda clean -a - -# Add to the bashrc -RUN echo "alias python=\"python3\"" >> ~/.bashrc -RUN echo "conda activate training_cpp_2021" >> ~/.bashrc -RUN source ~/.bashrc -CMD ["/home/formation/miniconda3/bin/conda", "run", "-n", "training_cpp_2021", "jupyter", "lab", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root","--NotebookApp.token=''"] +# The code to run when container is started: +# Using informations from https://hub.docker.com/r/continuumio/miniconda3 and options used by Vicente in former Docker file based on Ubuntu. +ENTRYPOINT [ "conda", "run", "--no-capture-output", "-n", "training_cpp_2021", "jupyter", "lab", "--port=8888", "--ip=0.0.0.0", "--no-browser","--allow-root","--NotebookApp.token=''"] \ No newline at end of file -- GitLab