Sitemap

Sharing Your Python Projects with Docker: Jupyter Notebooks and Datasets Included

A Tutorial on how to save and load Docker images

--

Press enter or click to view image in full size
Photo by airfocus on Unsplash

When collaborating on data science or machine learning projects, getting someone else up and running with your code can be painful: dependency hell, version mismatches, missing datasets, and broken notebooks. Sound familiar?

Docker solves that problem by letting you package everything — your Jupyter notebooks, your Python environment, and your datasets — into a single image that “just works” anywhere.

In this tutorial, you’ll learn how to:

  • Create a Docker image that includes your Jupyter notebook, dataset, and Python environment.
  • Save the image to a file.
  • Share it with someone else so they can run your exact environment locally.

Let’s dive in.

🛠 Scenario Setup

Imagine this: Alice is working on a machine learning project. She has a notebook train_model.ipynb, a dataset data.csv, and uses a few Python libraries. She wants to share this with Bob, who should be able to run everything without installing packages or chasing bugs.

We’ll walk through:

  1. Alice creating a Docker image with her work.
  2. Saving it as a file and sharing it.
  3. Bob loading the image and running it.

🧑‍💻 Step 1: Prepare the Project

Let’s assume the project folder has:

my_project/

├── train_model.ipynb
├── data.csv
└── requirements.txt

requirements.txt:

pandas
scikit-learn
matplotlib

🐳 Step 2: Write the Dockerfile

Inside my_project/, create a file named Dockerfile:

FROM jupyter/base-notebook

COPY requirements.txt /tmp/
RUN pip install --no-cache-dir -r /tmp/requirements.txt

COPY . /home/jovyan/work/

WORKDIR /home/jovyan/work/

CMD ["start-notebook.sh", "--NotebookApp.token=''"]

This Dockerfile:

  • Starts from the official Jupyter base image.
  • Installs the required packages.
  • Copies all your files (notebooks, datasets) into the working directory.
  • Launches Jupyter Notebook without a token (you can add auth in a real scenario).

🔨 Step 3: Build the Docker Image

In the terminal:

cd my_project
docker build -t my_project_image .

Now Alice has a complete environment in a Docker image called my_project_image.

💾 Step 4: Save the Image to a File

Alice wants to share the image with Bob. She can export it as a .tar file:

docker save my_project_image -o my_project_image.tar

She can now send my_project_image.tar to Bob (via USB, network, cloud storage, etc.).

📥 Step 5: Bob Loads the Image

Once Bob receives the file, he can load it into Docker:

docker load -i my_project_image.tar

Docker now knows about the image my_project_image.

🚀 Step 6: Bob Runs the Project

To run the image and launch Jupyter:

docker run -p 8888:8888 my_project_image

Bob can now open http://localhost:8888 in his browser and work with the notebook exactly as Alice did.

✅ Takeaways

  • Docker is a powerful tool for sharing Python environments that just work.
  • With a Docker image, you avoid dependency issues, environment setup, and version mismatches.
  • Sharing your work becomes as simple as sharing a file.

This approach is great for:

  • Team collaboration
  • Reproducible research
  • Teaching or workshops
  • Archiving work with guaranteed reproducibility

🔚 Final Notes

In real-world scenarios, you might:

  • Push your image to Docker Hub for easier sharing.
  • Use Docker Compose for more complex setups (e.g., database + app).
  • Add authentication or security measures.

Want the project files or have questions? Drop them in the comments or reach out!

--

--

George Pipis
George Pipis

Written by George Pipis

Sr. Director, Data Scientist @ Persado | Co-founder of the Data Science blog: https://predictivehacks.com/