Build Jupyter Lab (Python) environment with Docker

What was achieved

Since I was able to build the following environment with Docker, I summarized the flow from Docker image build to JupyterLab startup

--Easy to switch Python versions (Python3 ⇄ Python2) --Easy to start JupyterLab [^ 1] --You can delete the environment as soon as you no longer need it. --I want to easily build an environment on Mac and Windows

The environment actually built

Docker image

Account login is required to obtain it. Please also install Docker Desktop. In addition, this time I used python of Docker Official Images [^ 2]

Dockerfile --Select Docker image

Store Docker files in any directory

Docker image Settings
Python3 python:3
Python2 python:2

Dockerfile


FROM python:3
WORKDIR /usr/src/app
RUN pip install --upgrade pip
RUN pip install numpy scipy matplotlib ipython scikit-learn pandas pillow mglearn
RUN pip install jupyterlab
RUN jupyter serverextension enable --py jupyterlab

docker-compose.yml

Store docker-compose file in any directory

Setting items Settings
Host side shared folder /Users/User_Name/Docker/JupyterLab/codes
Shared folder on the container side /home/JupyterLab/codes
JupyterLab login password[^3] --NotebookApp.notebook_dir='/home/JupyterLab/codes'
JupyterLab home directory --NotebookApp.notebook_dir='/home/JupyterLab/codes'
Docker container name jupyterlab

docker-compose.yml


version: '3'
services:
  jupyterlab:
    container_name: 'jupyterlab'
    image: jupyterlab
    build:
      context: .
      dockerfile: "Dockerfile"
    user: root
    volumes:
      - jupyterlab-dir:/home/JupyterLab/codes
    ports:
      - "8888:8888"
    environment:
      TZ: Asia/Tokyo
    command: jupyter lab --ip=0.0.0.0 --allow-root --no-browser --NotebookApp.notebook_dir='/home/JupyterLab/codes' --NotebookApp.token='○○○'
volumes:
  jupyterlab-dir:
    driver_opts:
      type: none
      device: /Users/MacLover/Docker/JupyterLab/codes
      o: bind

Docker image build

Build the image with the following command

Terminal or PowerShell

docker-compose build

Check the image

Terminal or PowerShell

docker images

It's okay if the image jupyterlab is displayed

Start Docker container

The next time you use Jupyter Lab, start it with the following command

Terminal or PowerShell

docker-compose up

When stopping, ctrl + c on the terminal

Access Jupyter Lab

Access the following URL and enter the password to display the Jupyter Lab screen. The code created on JupyterLab (ipynb file, etc.) is output to the shared folder on the host side, so even if you delete the container, the created code will not be deleted.

http://localhost:8888/

[^ 1]: Instead of adding a long option with docker run, I described it in the configuration file (Dockerfile and docker-compose.yml) and devised to start it only with ** docker-compose up **

[^ 2]: Initially, I was thinking of "jupyter / datascience-notebook", but when I tried it on Windows, a kernel error occurred when starting Jupyter Lab, so I simply used a Python-only image.

[^ 3]: When writing a hashed password instead of plain text, change "--NotebookApp.token ='○○○'" to "--NotebookApp.password ='sha1: ○○○'". Please change

Recommended Posts

Build Jupyter Lab (Python) environment with Docker
Build Mysql + Python environment with docker
[Python] Build a Django development environment with Docker
Build python3 environment with ubuntu 16.04
Prepare python3 environment with Docker
Build python environment with direnv
Build PyPy and Python execution environment with Docker
Comfortable Jupyter Lab (Python) analysis environment created with Docker + VSCode + Remote Container
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Build python virtual environment with virtualenv
Build PyPy execution environment with Docker
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
Build the execution environment of Jupyter Lab
Create Python + uWSGI + Nginx environment with Docker
Build Python environment with Anaconda on Mac
[Linux] Build a jenkins environment with Docker
Launch environment with LineBot + Heroku + Docker + Python
Build a basic Data Science environment (Jupyter, Python, R, Julia, standard library) with Docker.
Build a python virtual environment with pyenv
Build a modern Python environment with Neovim
Build AI / machine learning environment with Python
Build NGINX + NGINX Unit + MySQL environment with Docker
[Linux] Build a Docker environment with Amazon Linux 2
Create an arbitrary machine learning environment with GCP + Docker + Jupyter Lab
How to build Python and Jupyter execution environment with VS Code
Install Python Jupyter lab
Use python with docker
Python environment with docker-compose
Virtual environment with Python 3.6
Prepare the execution environment of Python3 with Docker
Build Django + NGINX + PostgreSQL development environment with Docker
Analytical environment construction with Docker (jupyter notebook + PostgreSQL)
Build python environment with pyenv on EC2 (ubuntu)
Build Python development environment with Visual Studio Code
Go (Echo) Go Modules × Build development environment with Docker
Build a python environment with ansible on centos6
Create a python3 build environment with Sublime Text3
Create Nginx + uWSGI + Python (Django) environment with docker
Build a Python environment with OSX El capitan
Quickly build a Python Django environment with IntelliJ
Build a Python machine learning environment with a container
Build a python execution environment with VS Code
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]
Install Python environment with Anaconda
Japanese can be used with Python in Docker environment
Manage python environment with virtualenv
Build a python virtual environment with virtualenv and virtualenvwrapper
[Python] OpenCV environment construction with Docker (cv2.imshow () also works)
Build a python environment for each directory with pyenv-virtualenv
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Trial and error]
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
Build Python environment on Windows
How to build a Django (python) environment on docker
[ev3dev × Python] Build ev3dev development environment
Build a machine learning application development environment with Python
Build a python virtual environment with virtualenv and virtualenvwrapper
Build python environment on windows
Try running Python with Try Jupyter
Python local development environment construction template [Flask / Django / Jupyter with Docker + VS Code]
Build a Python environment offline
Let's build git-cat with Python