Jupyter-notebook is my favorite tool. The environment is a little troublesome. In fact, the best way to deploy jupyter web is in the cloud. It can be used anywhere at a time. Now the cloud servers are quite expensive. After docker came out, I thought about putting jupyter-notebook in the container.
Docker and System
Students who have been installed can ignore this section. I like to use ubuntu, so the host system is ubuntu, and the system in the docker container is ubuntu. The docker version installed by the ubuntu apt-get source by default is not the latest version, and the latest version of the docker needs to be installed by adding the source. Reference link
#https access capability with ubuntu apt $ sudo apt-get install apt-transport-https #Add the access Key to Docker's official database to your local system $ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 #Add docker database address to apt source list $ sudo bash -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" #install $ sudo apt-get update $ sudo apt-get install lxc-docker
When Docker is installed, you need to pull a Ubuntu version image. I pull ubuntu:14.04.
docker pull ubuntu:14.04
Starting container
Containers are where jupyter-notebook is stored. What we need to do is start a container based on a streamlined ubuntu image and install sshd, a remote login tool.
Let the container start as an interactive virtual terminal. If you need to use a different DNS server configuration from the host, you can specify the DNS server using the -- dns parameter. Otherwise, the newly launched docker container will copy the host's / etc/resolv.conf.
docker run -i -t ubuntu:14.04 /bin/bash
The process of installing sshd is relatively simple. I usually install openssh-server.
sudo apt-get install openssh-server
Then edit its configuration file / etc/ssh/sshd_config, comment out the "Permit Root Login without-password" in the configuration file, and add a "Permit Root Login yes" so that root users can login remotely. Then mirror the container with the sshd installed.
Then, the container is started based on the new image, and the ssh port is mapped to the host by port mapping. Then, the docker container is logged in by ssh specifying the port. The default port number for jupyter-notebook is 8888, which can also be considered in advance, where several external ports are mapped.
docker run -d -p 30001:22 --name jupyter-notebook ubuntu:14.04-sshd /usr/sbin/sshd -D
Install jupyter
This process is basically the same as installing jupyter on the ubuntu system, but ubuntu in the container is the simplest environment without installing the python-dev package.
#Update apt-get environment apt-get update #Install the python dev package apt-get install python-dev #Install jupyter pip install jupyter
The installation process should be noted that due to wall reasons, the source of ubuntu and pip are replaced by domestic sources. I use Netease as the source of ubuntu and Tsinghua as the source of pip.
Using jupyter
By default, jupyter can only be accessed through local addresses. It should be configured to allow remote access to jupyter. When remote access is opened, passwords need to be set. Jupyter configuration files only support encrypted ciphertext passwords.
#Generate the jupyter configuration file, which generates the configuration file. jupyter/jupyter_notebook_config.py jupyter notebook --generate-config #Using ipython to generate passwords In [1]: from notebook.auth import passwd In [2]: passwd() Enter password: Verify password: Out[2]: 'sha1:38a5ecdf288b:c82dace8d3c7a212ec0bd49bbb99c9af3bae076e' #To modify the following parameters in the configuration file. jupyter/jupyter_notebook_config.py c.NotebookApp.ip='*' #Bind all addresses c.NotebookApp.password = u'The password just generated' c.NotebookApp.open_browser = False #Whether to open automatically in the browser after booting c.NotebookApp.port =8888 #Specify an access port, default 8888, note that it corresponds to the docker port mapped
Once the configuration is complete, you can start jupyter with the command jupyter notebook, and then you can see a super simple jupyter login interface. Enter your password and you can start using jupyter.
extend
If you want big data analysis, you need to install a lot of big data related packages.
I still use pandas/scikit-learn most of jupyter, so I will continue to install these two packages, you can continue to install the python packages you want according to your needs.
#Install numpy, there will be c file compilation during installation, may report some errors, but does not affect the final results pip install numpy #Installation of scipy will result in compilation of c files during installation, which may cause some errors, but will not affect the final results. pip install scipy #Install matplotlib pip install matplotlib #Install pandas pip install pandas pip install scikit-learn
In general, the package management of pip is relatively good, except for a bunch of errors in numpy and scipy compilation time, the overall installation process is relatively smooth.