6

Jupyter Notebook

 3 years ago
source link: https://towardsdatascience.com/jupyter-notebook-in-a-docker-container-on-aws-ec2-instance-7efc51459d6f
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Jupyter Notebook in an AWS EC2 Instance using Docker Image

Best of all possible worlds for Data Science and Machine Learning professionals

Image for post
Image for post
Photo by Zeshalyn Capindo on Unsplash

Most of the data science and machine learning professionals are in love with the Jupyter notebook. Barring few anomalies, most of the data science and machine learning works are happening in the cloud. So there is no option but to use Jupyter on the cloud.

In my previous article, I explained how you can download the Jupyter notebook on AWS Linux instance and access it on your client machine using Xming and X11 forwarding. Below is the link to that article

In this article, I am explaining how to access the Jupyter notebook in AWS EC2 instance directly through a Docker image. No need to install Anaconda or Jupyter in the AWS EC2 instance.

I am assuming that you already have an AWS EC2 instance and know how to access it through Putty

Prerequisite Tools

Make sure you have the latest version of the default OS packages. Especially check if firewall related packages are installed and configured. I am using a Redhat Linux instance on AWS EC2.

The first thing to confirm is iptables-services are installed. If not, install it through yum

sudo yum install iptables-services
Image for post
Image for post
Image by Author

Docker Engine Installation

Now you are ready to install the Docker engine. I have followed instructions from the below link for installing the Docker engine on my Red Hat Linux instance. If you have an instance with a different operating system, please check the steps for that operating system in the below link.

a. First thing first; run the below command to install all the yum utilities

sudo yum install -y yum-utils
Image for post
Image for post
Image by Author

b. Get the latest docker repository

sudo yum-config-manager --add-repo  https://download.docker.com/linux/centos/docker-ce.repo
Image for post
Image for post

c. And now install the latest version of docker engine and container

sudo yum install docker-ce docker-ce-cli containerd.io
Image for post
Image for post
Image by Author

d. Start the docker service.

sudo systemctl start docker.service

If you do not get any error message, your docker service has started successfully.

Image for post
Image for post
Image by Author

e. You can also check the status of the docker service.

sudo systemctl status docker.service
Image for post
Image for post
Image by Author

Congratulations!! You have successfully installed a docker engine. Now you are ready to pull the Jupyter Notebook image.

Jupyter Notebook

It’s time to pull the Jupyter notebook image.

a. Run the below command to pull the docker image and start Jupyter notebook.

sudo docker run -p 8888:8888 jupyter/scipy-notebook

Wait for the image download and pull to complete.

Image for post
Image for post
Image by Author

You will get the message indicating Jupyter notebook is running and it will contain a link to Jupyter notebook.

Image for post
Image for post
Image by Author

b. Copy the link and remove the 127.0.0.1 with the public IP address of your instance. You can see the public IP address for your instance in EC2 Instance Connect tab.

Image for post
Image for post
Image by Author

c. If you get time out a message or a site can’t be reached message, your instance might not be allowing connection at port 8888.

Image for post
Image for post
Image by Author

d. Go to the security tab of your AWS instance and click on the security groups name.

Image for post
Image for post
Image by Author

e. Click on Edi inbound rules button.

Image for post
Image for post
Image by Author

e. Add a rule for port 8888 as shown below and save the rule.

Image for post
Image for post
Image by Author

f. Now refresh your browser. Jupyter notebook will come up.

Image for post
Image for post
Image by Author

Congratulations!! Your Jupyter notebook is waiting for your next data science or machine learning adventure!

Conclusion

Cloud and Docker images are becoming an inevitable part of data science and machine learning professionals' life. Docker images are like work already done for you. Use it as much as possible to reduce your turnaround time in projects.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK