skip to Main Content

I’m using the command bellow to execute Anaconda inside a docker container.
But I want to transform it in a Dockerfile so I could just send a docker run to up the application.

The idea is simple: run it locally in port 8888 reading <<my_directory>>.

Don’t need to execute the big command bellow every time.

How could I do that?

docker run -i -t -p 8888:8888 -v <<my_directory>>:/opt/notebooks continuumio/anaconda3 /bin/bash -c "
    conda install jupyter -y --quiet && 
    mkdir -p /opt/notebooks && 
    jupyter notebook 
    --notebook-dir=/opt/notebooks --ip='*' --port=8888 
    --no-browser --allow-root"

2

Answers


  1. Have you looked at this: running conda's jupyter on docker
    alternatively, you could try something like:

    FROM continuumio/anaconda3:2020.11
    RUN apt-get update 
    RUN conda install jupyter -y --quiet && mkdir -p /opt/notebooks && jupyter notebook
    EXPOSE 8888
    ENTRYPOINT["jupyter", "notebook", "--no-browser","--ip=0.0.0.0","--NotebookApp.token=''","--NotebookApp.password=''"]
    

    check out this: https://towardsdatascience.com/making-docker-and-conda-play-well-together-eda0ff995e3c
    and this the dockerfile and explanation in this: https://github.com/NewportDataProject/data-night

    Login or Signup to reply.
  2. Since you cannot use volumes in Dockerfile, I recommend using docker-compose and Dockerfile both.

    Create a file called docker-compose.yml beside your Dockerfile as the following:

    version: '3'
    
    services:
        some_name:
            build: .
            ports:
                - 8888:8888
            volumes:
                - <my_directory>:/opt/notebooks
    

    Now add these lines to your Dockerfile:

    FROM continuumio/anaconda3
    RUN conda install jupyter -y --quiet && 
    mkdir -p /opt/notebooks && 
    jupyter notebook 
    --notebook-dir=/opt/notebooks --ip='*' --port=8888 
    --no-browser --allow-root"
    

    But if you want to your bash -c ... command run and make up your container, then change your Dockerfile to this:

    FROM continuumio/anaconda3
    CMD conda install jupyter -y --quiet && 
    mkdir -p /opt/notebooks && 
    jupyter notebook 
    --notebook-dir=/opt/notebooks --ip='*' --port=8888 
    --no-browser --allow-root"
    

    And finally run:

    docker-compose up -d`
    

    to run in detach mode.

    Or run:

    docker-compose up
    

    to run and see the logs.

    This is how you can install docker-compose: https://docs.docker.com/compose/install/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search