avatarGeorge Pipis

Summary

The website content provides a guide on how to efficiently work with Docker Jupyter Notebooks by syncing them with a local computer, using Jupyter Docker Stacks and a single command to mount the local directory to the Docker container.

Abstract

The article titled "How to Sync your Working Environment with Docker Jupyter Notebooks" offers a solution for data scientists who prefer using Jupyter notebooks but may not have the Anaconda distribution installed on their work machine. It introduces the use of Docker Jupyter Notebooks as an alternative to Google Colab, detailing how to leverage Jupyter Docker Stacks for running Jupyter applications in a Docker container. The author explains the process of synchronizing local data with the Docker container, ensuring that both input data and analysis outputs are seamlessly shared between the local environment and the container. A single command is provided to mount the local working directory to the container, demonstrating the ease of working with Docker Jupyter Notebooks as if they were on the local machine. The article also covers how to stop the Docker container once the work is completed, emphasizing the practicality of this approach for data scientists.

Opinions

  • The author, George Pipis, suggests that using Docker Jupyter Notebooks is a convenient method for data scientists who cannot or do not want to install heavy distributions like Anaconda on their local machines.
  • The article promotes the use of Jupyter Docker Stacks as a ready-to-run solution that can be easily set up and synchronized with local files, enhancing work efficiency.
  • The author implies that working with Docker Jupyter Notebooks is not only limited to individual use but can also be scaled for team collaboration through JupyterHub.
  • By providing a step-by-step guide and screenshots, the author conveys that the process of syncing local environments with Docker containers is user-friendly and accessible even to those who may not be familiar with Docker.
  • The article encourages readers to join Medium through the author's referral link, indicating a potential affiliate relationship.

DevOps

How to Sync your Working Environment with Docker Jupyter Notebooks

How to work efficiently with Docker Jupyter Notebooks from your local PC

Image on Unsplash

Data Scientists love to work with Jupyter notebooks. It is possible that in the machine that you have to work on, the Jupyter Notebook with the Anaconda distribution is not available and you do not want to install something so heavy for a one-off task. One option could be to work with Colab, and another option, that we will discuss right now, is to work with Dockers.

Jupyter Docker Stacks

Jupyter Docker Stacks are a set of ready-to-run Docker images containing Jupyter applications, enabling us to run Jupyter Notebooks and Jupyter Labs in a local Docker container and JupyterLab servers for a team using JupyterHub. Finally, we can create our own Dockerfiles.

Sync your Local Computer with the Docker Jupyter Notebook Container

Assume that the data that you want to work with are in your local PC and you need to load them to the Docker container and moreover, the output of the analysis which will be generated in the container, needs to be copied to your local PC. In other words, we need to synchronize the local working environment with the Jupyter Notebook Docker Container. So let’s assume that our working directory is under C:\ForTheBlog\jupyter_docker (windows) where there are the mydata.tsv file.

Our goal is to synchronize this folder with the Jupyter Notebook.

A Single Command

Assuming that you have installed Docker, then it requires a single command to synchronize your local directory with the Jupyter Notebook Docker Container

docker run -it -p 8888:8888 -v //c/ForTheBlog/jupyter_docker:/home/jovyan/work/tmp --rm --name jupyter jupyter/datascience-notebook

Where:

  1. //c/ForTheBlog/jupyter_docker is the path of my local folder. Notice that I use windows that is why I have written the path like that (//c/…).
  2. -v is the flag to mount the volume
  3. /home/jovyan/work/tmp is the directory of the container that we want to sync. Notice that the /home/jovyan/work already exists.
  4. jupyter/datascience-notebook is the Docker imager

As we can see the mydata.tsv is insider the Docker container.

Let’s create a new file now within the Docker container.

As you can see, we created two new files, the MyNotebook.ipynb and the mydata.csv. Not surprisingly, these two new files are also in our local folder!

Stop the Container

If you are done, you can stop the container. First, you need to find the container id and then stop it.

docker ps -a
docker stop 5ccf

The Takeaway

With a single line of code, you can work with Jupyter Notebooks in Dockers like working on your local computer.

Originally posted by Predictive Hacks

Docker
Jupyter Notebook
Python
Recommended from ReadMedium
avatarVengateswaran Arunachalam
Docker + Spark + Jupyter Notebook Setup

Introduction:

4 min read