dockerjupyter-notebookkaggle

Is there a way to install a package in the Docker image file without rebuilding it again?


So I built a docker image file and now when I try to run it , it gives me the error :

Failed to run image. Error: (HTTP code 400) unexpected - failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "jupyter": executable file not found in $PATH: unknown

Dockerfile :

FROM python:3.10-slim-bullseye

WORKDIR /project_dir

RUN apt-get update \
    && apt-get install -y build-essential unzip \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN pip install kaggle

COPY requirements.txt /project_dir/

RUN pip install --no-cache-dir -r requirements.txt

COPY kaggle.json /root/.kaggle/kaggle.json

RUN chmod 600 /root/.kaggle/kaggle.json

RUN kaggle datasets download -d odins0n/ucf-crime-dataset -p /app/kaggle_dataset/ \
    && unzip /app/kaggle_dataset/ucf-crime-dataset.zip -d /app/kaggle_dataset/ \
    && rm /app/kaggle_dataset/ucf-crime-dataset.zip

COPY . /project_dir/

CMD ["jupyter", "notebook", "--ip='*'", "--port=8888", "--no-browser", "--allow-root"]

So now I have to modify my dockerfile and include pip install jupyter in it. Now I want to know if there is any way by which I can speed up the build process or straight up skip it and directly install Jupyter in the container.


Solution

  • A container is a running image. You can add anything to a container but these changes are not persistent. In this case you want to persist your correction so you have to rebuild the image; in other words you have to modify the image, not the container. This is how Docker works. Once you have a correct image you can create containers from it in any environment.

    Note, however, that the Docker build cache will help you to speed up the build process: the lines of the Dockerfile that precede your correction will be executed quickly after the first build.