Write it down while it’s hot and give it to your future self

preface

Recently, I have been studying machine learning. In order to facilitate the access to the same learning resources in different places, ensure the continuity of learning progress, and eliminate the need to build the environment repeatedly, so as to reduce the learning cost, it is necessary to build an online learning platform to ensure that you can quickly enter the learning state anywhere. With the help of Jupyter, my needs can be perfectly met.

In addition, considering the convenience of porting, the docker method will be adopted to build and deploy the platform.

Necessary documents

Dockerfile

First, write the Dockerfile file to build the Docker image

Note: Dockerfile needs to be in the same directory as sources.list

The FROM rackspacedot/python37 MAINTAINER arkMon RUN mv/etc/apt/sources list/etc/apt/sources list. Bak # replace apt for domestic sources, COPY./sources.list /etc/apt/ RUN apt-get update & apt-get upgrade -y # global.index-url https://mirrors.aliyun.com/pypi/simple/ RUN /usr/local/bin/python -m pip install --upgrade pip # RUN pip3 install matplotlib # Install Jupyter RUN pip3 install Jupyter RUN ipython3 kernel install # RUN pip3 install ipyWidgets # Install the Jupyter interface extension. RUN Jupyter nbexTension Enable --py widgetsnBexTension RUN echo "c. n. BookApp. open_browser = False" >> /root/. Jupyter /jupyter_notebook_config.py RUN echo "c.NotebookApp.notebook_dir = '/root/jupyter'" >> /root/.jupyter/jupyter_notebook_config.py RUN echo "c.NotebookApp.ip =  '*'" >> /root/.jupyter/jupyter_notebook_config.py RUN echo "c.NotebookApp.base_url = '/jupyter'" >> /root/.jupyter/jupyter_notebook_config.py RUN echo "c.NotebookApp.allow_origin = '*'" >> /root/.jupyter/jupyter_notebook_config.py # Install tensorflow RUN pip3 install --upgrade tensorflow RUN pip3 install Tensorflow # install keras RUN pip3 install keras # So let's say --allow-root CMD jupyter notebook --allow-rootCopy the code

sources.list

Use apt domestic Ali Cloud image to speed up APT-GET

$ cat sources.list

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted  universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverseCopy the code

Build the mirror

$ docker build .

Note: This command must run in the same directory as Dockerfile

Boot image

$ docker run -dti --name jupyter_keras -p 40000:8888 -v /data/workspace/docker-install/keras_jupyter/jupyter:/root/jupyter ${image_id}

Mount the /root/jupyter directory to the /data/workspace/docker-install/keras_jupyter/jupyter directory on the host.

  • On the one hand, you can edit the files in jupyter, persistent to the host, to ensure the security of data
  • On the other hand, you can then scale out load balancing by using the image to start multiple container copies, all mounted to the same directory on the host, and using nginx’s upstream feature for load balancing

External access

Address: http://HostIP:40000