dockerlinuxpython

Creating Docker Image for Jupyter Notebook

Below are the steps for creating docker image for running a Jupyter Notebook with the latest python module .  You can run this for any operating systems that supports docker. If you haven’t downloaded the docker desktop. Please do so from here

Creating a Docker image with Jupyter Notebook and Python involves several steps, including setting up a Dockerfile, building the image, and running a container. Here’s a basic guide on how to do it:

1. Install Docker: If you haven’t already, install Docker on your machine. You can download it from the official Docker website.

2. Create a Dockerfile: A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Here’s a simple example of a Dockerfile that sets up a Jupyter Notebook with Python:

# Use the latest official Python image as the base image
FROM python:latest

# Set the working directory in the container
WORKDIR /usr/src/app

# Create a non-root user and switch to it
RUN useradd -m myuser
ENV PATH=”/home/myuser/.local/bin:${PATH}”
USER myuser

# Copy files from the host to the container
COPY –chown=myuser:myuser path_to_your_files/ /usr/src/app/

# Install Jupyter Notebook as the non-root user
RUN pip install –user notebook

# Make port 8888 available to the world outside this container
EXPOSE 8888

# Run Jupyter Notebook as a non-root user
CMD [“jupyter”, “notebook”, “–ip=0.0.0.0”, “–port=8888”, “–no-browser”, “–NotebookApp.token=””]

3. Build the Docker Image Again: Save the modified Dockerfile and then build your Docker image again. Use the docker build command in the directory where your Dockerfile is located:

docker build -t jupyter-notebook .

4. This command builds a new Docker image using the updated Dockerfile. Replace jupyter-notebook with your preferred image name.
Run the Docker Container: After successfully building the image, run the container:

docker run -p 8888:8888 jupyter-notebook

5. You should see a URL on the log . Cut and paste this on a browser to get to the webUI for Jupyter Notebook

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.