Write a dockerfile to start jupyter-lab on ubuntu

Introduction

I took a docker course at udemy, so I will summarize a part of it as a memorandum. This time I would like to write the code to start jupyter-lab based on ubuntu in the docker file and actually create the container.

Described in dockerfile

dockerfile



# FROM =>Select a base image
FROM ubuntu:latest

# RUN =>Call a command
# apt-Upgrade get and install the required packages
RUN apt-get update
RUN apt-get install -y \
    wget \ 
    vim

# WORKDIR =>Create and move an arbitrary directory directly under the root on the container side
WORKDIR /opt

#Install anaconda3 and delete the original executable file
# wget =>Specify the URL to download the file
# sh =>Run a shell script
# -b =>Avoid interactive operations
#  -p =>Specify the installation destination
#  rm =>Delete the specified file
#  -f =>Forcibly execute
RUN wget https://repo.continuum.io/archive/Anaconda3-2019.10-Linux-x86_64.sh && \
    sh /opt/Anaconda3-2019.10-Linux-x86_64.sh -b -p /opt/anaconda3 && \
    rm -f Anaconda3-2019.10-Linux-x86_64.sh

#PATH of anaconda3
#  ENV =>Change environment variables
ENV PATH /opt/anaconda3/bin:$PATH

#pip upgrade
RUN pip install --upgrade pip

#Return directly under root
WORKDIR /

#Open jupyter lab when container starts
#  CMD =>Specify the command to be executed when the container starts
#  "jupyter", "lab" =>Launch jupyter lab
#  "--ip=0.0.0.0" =>Remove ip restrictions
#  "--allow-root" =>Allow root user, not good for security
#  "LabApp.token=''" = >It can be started without a token. Not good for security
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--allow-root", "--LabApp.token=''"]

Build image

Run in the directory where the Dockerfile is located


docker build -t my-anaconda .

-t Give the image you want to build any name you like.

. The directory where the dockerfile is located is specified. This time, specify the current directory.

Start container


docker run -it \
-p 8888:8888 \
--rm \
--name my-container(Any)\
-v Desktop/ds_python:/opt \
my-anaconda

See below for this part [https://qiita.com/kajima/items/178611c4c405267271a6](https://qiita.com/kajima/items/178611c4c405267271a6)

When you run this container

I 11:42:41.250 LabApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 11:42:41.535 LabApp] All authentication is disabled.  Anyone who can connect to this server will be able to run code.
[I 11:42:41.546 LabApp] JupyterLab extension loaded from /opt/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 11:42:41.546 LabApp] JupyterLab application directory is /opt/anaconda3/share/jupyter/lab
[I 11:42:41.548 LabApp] Serving notebooks from local directory: /
[I 11:42:41.548 LabApp] The Jupyter Notebook is running at:
[I 11:42:41.548 LabApp] http://23a5a126fd40:8888/
[I 11:42:41.548 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 11:42:41.552 LabApp] No web browser found: could not locate runnable browser.

OK when such a screen appears

After that, enter localhost: 8888 in the web browser and check it.
スクリーンショット 2020-08-27 20.51.30.png
OK when this comes out on the screen

At the end

After that, if you want anaconda to have any library or package, you can install it by writing RUN in the docker file. Next, I would like to write a docker file for web development.

reference

https://qiita.com/komiya_____/items/96c14485eb035701e218 https://www.udemy.com/course/aidocker/learn/lecture/20311429#overview

Recommended Posts

Write a dockerfile to start jupyter-lab on ubuntu
[Basic] How to write a Dockerfile Self-learning ②
How to write dockerfile
How to build a Pytorch environment on Ubuntu
To write a user-oriented program (1)
[Note] Flow from docker installation to JupyterLab startup on ubuntu
I made a Dockerfile to start Glassfish 5 using Oracle Java
How to use Bio-Formats on Ubuntu 20.04
How to write a ternary operator
Rails on Tiles (how to write)
Build a XAMPP environment on Ubuntu
How to install WildFly on Ubuntu 18.04
Preparing to use electron-react-boilerplate on Ubuntu 20.4
How to build vim on Ubuntu 20.04
A story of frustration trying to create a penetration environment on Ubuntu 20.04
A note when I was addicted to converting Ubuntu on WSL1 to WSL2
I want to write a nice build.gradle
Minimal steps to set up a Ruby environment with rbenv on Ubuntu 20.04
How to install production Metabase on Ubuntu
[Introduction to Java] How to write a Java program
I want to write a unit test!
I want to install PHP 7.2 on Ubuntu 20.04.
[Ruby] Building a Ruby development environment on Ubuntu
How to change the timezone on Ubuntu
Sample to start Ubuntu with Deployment with client-go
[SpringBoot] How to write a controller test
How to write and explain Dockerfile, docker-compose
Serially connect to Ubuntu on Raspberry Pi
Rails: How to write a rake task nicely
Two ways to start a thread in Java + @
[Rails] How to write when making a subquery
How to deploy a container on AWS Lambda
How to configure ubuntu to be used on GCP
How to install network drivers on standalone Ubuntu
Building a Hadoop cluster (Cloudera Manager on Ubuntu 18.04)
Write to a file using ShiftJIS-Read a file (Kotlin / JVM)
Build a DHCP and NAT router on Ubuntu 16.04
How to install NVIDIA driver on Ubuntu 18.04 (Note)
I want to simply write a repeating string
How to install multiple JDKs on Ubuntu 18.04 LTS
Rip a CD to MP3 with Ubuntu 18.04 LTS
[Java] Memo on how to write the source
How to run NullpoMino 7.5.0 on Ubuntu 20.04.1 64bit version
Notes on how to write comments in English
tmux on Ubuntu
[Introduction] Try to create a Ruby on Rails application
[Ruby on Rails] How to write enum in Japanese
How to write a unit test for Spring Boot 2
java: How to write a generic type list [Note]
How to make JavaScript work on a specific page
How to install NVIDIA driver on Ubuntu ssh destination
Steps to set up a VNC server on CentOS 8.3
How to write a date comparison search in Rails
[Java] How to execute tasks on a regular basis
How to start TOMCAT by specifying JAVA_HOME on Windows
What to see when IntelliJ doesn't start on Mac
How to write a core mod in Minecraft Forge 1.15.2
[Java] How to start a new line with StringBuilder