Until you start Jupyter in a machine learning container with Docker + Miniconda

2019/11/19

Build a Docker environment for machine learning and data science using the official image of Miniconda. We have summarized the steps from installing Docker to installing the python package in the container and opening Jupyter notebook.

The merit of building an environment for machine learning with docker is

  • You can quickly build an environment for deep learning frameworks with severe library / version differences.
  • (For Ubuntu) You can easily use the GPU version of Tensorflow / LightGBM, which is troublesome to install.
  • (For Windows and Mac) Only Linux-based libraries can be used.
  • Even if the Conda environment is broken, it can be recovered immediately

Such as it will be mentioned.

Docker installation

Click here to install Docker on each OS.
Ubuntu,Windows pro,Mac

GPU containers are only available on Ubuntu with Docker. If you only have a Windows or Mac OS computer and want to use a GPU container, you can boot Ubuntu from an external SSD.

Get Miniconda image / Create container

The official Docker image (Anaconda 2 or 3, Miniconda 2 or 3) is below.https://github.com/ContinuumIO/docker-images

You can get the Miniconda 3 (python 3.7 based Miniconda) image from your terminal with the following command:

# docker Create a place to put files shared with the container mkdir -p docker / miniconda # Get the official image of miniconda3 docker pull continuumio / miniconda3 # Start the miniconda container docker run --name miniconda3 -it -p 8888 : 8888 -v / home / [USER name] / docker / miniconda: / home continuumio / miniconda3 / bin / bash

Explanation of options when docker run
--name : Name to give to the container to be made
-it: Connect the command prompt of the container and the host
-p : Connect the port of the host and the container: You can open the jupyter notebook from the browser
-v: Share the host folder (here / home / docker / miniconda) with / home in the container.First "mkdir -p docker/minicondaIf you put a file (analysis data, etc.) in the folder created in ", you can share it with the container.

Here, for the time being-vThe shared folder is mounted with the option. With jupyter notebook, files can be uploaded and downloaded into the container via a browser, so it may not be necessary.

Working inside a Miniconda container

Since I put it in the command prompt in the container with the previous command, install the package (create a virtual environment if necessary).

# Create virtual environment for ML conda create -n ML # Install machine learning / data science related packages conda install numpy scipy pandas matplotlib seaborn bokeh jupyter jupyterlab scikit-learn 

Launch Jupyter notebook in the container

Open # jupyter notebook jupyter notebook --port 8888 --ip = 0.0.0.0 --allow-root # For jupyter lab, do the following jupyter lab --port 8888 --ip = 0.0.0.0 --allow-root

You can open jupyter by entering the output URL in your browser.

"Ctrl + C" to exit jupyter
To re-enter the container, clickdocker exec -it コンテナID /bin/bash'
To save the created Miniconda container as an image, clickdocker commit CONTAINER_ID 保存するイメージ名'