Jupyter Lab as a container
Jupyter container

Jupyter Lab as a container


This article is focused on containerizing Jupyter Notebook inside the docker container with a fully-fledged develop environment for data science students.

But... why?

The answer is why not? I mean being a data science student you will be working on multiple projects or maybe the one who needs his custom development environment ready on the fly... without worrying about the development environment that can take your precious time to set it up locally...

...Imagine if you have a program that can do the same thing for you with only just few commands

Disclaimer: This article is primarily focused for the folks who have little to no knowledge on docker but they want to isolate the development by containerizing it.

Let's start...

Prerequisites:

No alt text provided for this image
Prerequisites

  • Docker installed on your system. if it's not check out guide
  • Internet Connectivity
  • Knowledge of pip troubleshooting (It helps a lot)
  • account with root privileges



So we will start by creating a working directory. For that we will start by typing...

$ mkdir jupyter-lab && cd jupyter-lab && pwd        

By above command we are creating a directory called 'jupyter-lab', then navigating to the directory using 'cd' command and to verify we are printing the current working directory using 'pwd' command.

No alt text provided for this image

Now, inside the directory create a file named 'Dockerfile' S using any text editor you like for my sake I am using vim. to do that enter the following command and hit enter.

$ vi Dockerfile        

Append the following content to the Dockerfile and save it.

No alt text provided for this image
Docekrfile

Now, for development requirement let's create a requirements.txt file that later will be used by pip to install all of your library dependencies at once

Again, open a text editor by typing the command

$ vi requirements.txt        

You can use a different text editor but keep in mind if you're using the same configuration for the Dockerfile as mentioned above, then place the requirements.txt file in the same directory or you have to define the whole directory path where the file lives and the path where you want the file inside the docker container. In my case I am putting the file in root directory for demonstration purposes.

List all the dependencies as per your requirements. For my case I used basic libraries. Since I am not learning Data Science just for demontration purposes

Note: Don't forget to list notebook inside the reqirements file it will give error while running the jupyter-lab

No alt text provided for this image
requirement.txt

Now save the files. If you're following along with me then your directory will look like this:

No alt text provided for this image
directory contents

Now, all the configurations are defined let's start by building our container image for that type the command mentioned below:

$ sudo docker build -t jupyter-lab .        

And press enter key. Now if you started getting output like below then it indicates that the docker has started building the image.

No alt text provided for this image
Docker building the image

Now grab a cup of coffee or tea or maybe you can finish your work or if you're working for a long time you can go for a walk and take a breadth as well, just say yourself

No alt text provided for this image
Yeah... you deserve

I utilized the time by framing this blog in the meantime.

No alt text provided for this image
Me framing the blog

But remember one thing...

No alt text provided for this image

Why...? Because the job isn't finished yet.

So after a while you will see the output like below:

No alt text provided for this image
Docker buit the image successfully

It indicates that the docker has built the image successfully...

Now, to run the docker type command:

$ sudo docker run -it -p 8888:8888 jupyter-lab        

It will run the container in terminal mode and maps the default port used by jupyter (i.e. 8888) container to the host port (8888 in this case) you can verify if you're inside the container simply by looking at the shell prompt

No alt text provided for this image
Before
No alt text provided for this image
After

Now just enter the command to run Jupyter Notebook

$ notebook        

And you will see the output as usual when you start the Notebook inside the terminal.

No alt text provided for this image
Jupyter notebook running as a container

Now copy the token highlighted (with white background)

  • Open the browser in your host system
  • Type 'localhost:8888/tree' Inside the URL bar

You'll see the page like below

No alt text provided for this image
Jupyter Notebook page when opened for the first time

Now paste the Token copied.

Or it's better to set a new password now by pasting the token to the field after scrolling the page a bit so next time you don't have to copy paste the token again. For that paste the token and set the password as below:

No alt text provided for this image
Setting up the password

Now, click on 'log in and set new password button.

You will see the Jupyter Notebook default directory page

No alt text provided for this image

What are you waiting for... Go and start developing your ideas into reality.

No alt text provided for this image
Congratulations!!!

Wait...

Hold on...

You didn't told me what the heck is going on...? My Development Environment don't look like that

Actually, the answer to your question will be in my upcoming blog where I will be explaining the basics of Dockerfile with a little example of continuous development.

Till then overflow your stack

Or... You can check out my other Docker related blogs too

Other writeups


Thanks,

- SK -


要查看或添加评论,请登录

SAKSHAM TRIVEDI的更多文章

  • DNF5... It's time to rethink the package management.

    DNF5... It's time to rethink the package management.

    Hello Folks, It's been a while since I have written any article. Well here I am now.

  • File BackuP & Sync...

    File BackuP & Sync...

    Introduction In today's fast-paced world, seamless file sharing and synchronization are essential for efficient…

  • Simplifying SSH Connection: A Guide To Build Your Own Proxy Network

    Simplifying SSH Connection: A Guide To Build Your Own Proxy Network

    Establishing a secure SSH connection between Machine A and Machine F can be challenging, especially when intermediate…

  • Unleashing the Power of Linux: A Browser-Based Linux Experience

    Unleashing the Power of Linux: A Browser-Based Linux Experience

    To access Fedora Linux's graphical system in a browser using Apache Guacamole, you will need to set up Guacamole on a…

  • Gmail from Old Dog Terminal

    Gmail from Old Dog Terminal

    Mutt is used to send and receive email from your terminal, even if you're using hosted service such as Gmail. A…

  • Let's WhatsApp using Bash

    Let's WhatsApp using Bash

    S: AuthorAuthorIntroduction In today's fast-paced world, automation plays a crucial role in streamlining various tasks.…

    5 条评论
  • Ping... a message arrrived

    Ping... a message arrrived

    In this short tutorial, Here I am going to demonstrate chatting using ping command. For this first of all you need a…

    1 条评论
  • Containerized SSH Server

    Containerized SSH Server

    In this article I am going to demonstrate how to containerize SSH server so without any further explanation let's…

  • Mutiple Linux shells on a same system

    Mutiple Linux shells on a same system

    Recently I came across the question is there any possibility that multiple shells can be installed on the same system…

  • Launching graphical application inside the docker container

    Launching graphical application inside the docker container

    Hello guys, In this article I am going to discuss how to launch the graphical application inside the docker. So, for…

社区洞察

其他会员也浏览了