Construction of data analysis environment using Docker (personal memorandum)

Creating a Dockerfile

Dockerfile


FROM ubuntu:latest
# -answer yes to y when installing and install
RUN apt-get update && apt-get install -y \
#Used when a non-root user wants to type commands with root privileges on ubuntu
	sudo \
#Download data using http
	wget \
#Editor
	vim
#Where to save the anaconda installation
WORKDIR /opt
#Download the anaconda installation.
RUN wget https://repo.continuum.io/archive/Anaconda3-2019.10-Linux-x86_64.sh

** apt-get ** is ubuntu's package management tool, and if you describe the packages separately by "", it is easy to understand what is installed.

Build container with Dockerfile

-#This will download the ubuntu package and the anaconda installer in the opt directory.
% docker build .
-#Start the created container
% docker run -it container ID bash
-#"WORKDIR" is opt/Because there is a specification of "opt"
-#Make sure you have an instrument roller.
root@85a5e79aa6c2:/opt# ls
Anaconda3-2019.10-Linux-x86_64.sh
-#Execution of installer
# sh Anaconda3-2019.10-Linux-x86_64.sh
  1. Press and hold enter
  2. Answer yes
  3. You will be asked where to install it, so use / opt / anaconda3
  4. You will be asked if you want to init, so answer yes
  5. ** If "Thank you for installing Anaconda 3!" ** is displayed, it has been downloaded. However, "python" cannot be used because it is ** not passed through the path **.

To pass a pass

By adding a path to the environment variable $ PATH, the computer will search for the program from that path.

Checking environment variables

# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Find python

-#Move to the "anaconda3" directory
# cd anaconda3
-#Move to "bin" directory
# cd bin
-#Launch "python"
# ./python
-#Check the path
# pwd

You can see that Python has started. In other words, passing the path means passing "/ opt / anaconda3 / bin".

Pass through

-#Get out of python.
>>> exit()
-#Add path(=There is no half-width space on both sides of)
# Export PATH=/opt/anaconda3/bin:$PATH
-#Check the path
# echo $PATH
-#/opt/anaconda3/You can see that bin has been added.
/opt/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
-#Move to "opt"
# cd /opt
-#Confirmation of python startup
# python

By passing the path, you can see that Python also started in the "opt" directory.

Checking instrument roller options

-# sh -x installer file
# sh -x Anaconda3-2019.10-Linux-x86_64.sh

Anaconda2-2019.10-Linux-x86_64.sh shows the options available, this time using **-b ** and **-p **. **-b ** starts in batch mode. Used when using in Dockerfile. Avoid interactive operations. **-p ** defaults to ** "/ root / anaconda3" ** and can be installed anywhere by specifying it. Delete "anaconda3" again and check if it can be installed.

-#Removal of anaconda3
# rm -r anaconda3/
-#Download from the installer and create anaconda3 in the opt directory
# sh Anaconda3-2019.10-Linux-x86_64.sh -d -p /opt/anaconda3

It can be confirmed that the download was successful.

Update Dockerfile

Dockerfile


FROM ubuntu:latest
RUN apt-get update && apt-get install -y \
    sudo \
    wget \
    vim
WORKDIR /opt
#------------Change from here------------#
RUN wget https://repo.continuum.io/archive/Anaconda3-2019.10-Linux-x86_64.sh && \
#Download from the installer and create anaconda3 in the opt directory
    sh https://repo.continuum.io/archive/Anaconda3-2019.10-Linux-x86_64.sh -b -p /opt/anaconda3 && \
#Remove instrument roller
    rm -f Anaconda3-2019.10-Linux-x86_64.sh
#Pass through$PATH is self-referencing
ENV PATH /opt/anaconda3/bin:$PATH
#"Pip" is a tool for managing python packages
RUN pip install --upgrade pip
CMD [ "jupyter","lab","--ip=0.0.0.0","--allow-root","--LabApp.token=''" ]

Build container with Dockerfile

% docker build .
% docker run -p 8888:8888 Created container ID

This will launch jupyterlab in the container and confirm that you can connect with localhost: 8888.

File system sharing

-#Create a file to share because it can be anywhere
% mkdir ds_python
-#Check the path of the file to share
% pwd
-#The shared file of the container is the "work" directory this time. The container name is "my-lab」
% docker run -p 8888:8888 -v Path of files to share:/work --name my-lab created image name

Check with localhost: 8888 and make sure the "work" directory is created. Create some file in the work directory with jupyterlab, check the contents of the "ds_python" file on the host side, and confirm that the file created with jupyterlab exists.

Recommended Posts

Construction of data analysis environment using Docker (personal memorandum)
Data management using volume in Docker (personal memorandum)
Django development environment construction using Docker-compose (personal memorandum)
Rails environment construction with Docker (personal apocalypse)
Building a CICD pipeline using Docker (personal memorandum)
Kaggle environment construction using official Docker and vscode
A reminder of Docker and development environment construction
Rails Docker environment construction
Docker Machine (personal memorandum)
Docker network (personal memorandum)
MySQL 5.7 (Docker) environment construction memo
Redmine (Docker) environment construction memo
[Docker] Rails 5.2 environment construction with docker
Docker × Spring Boot environment construction
[Docker] postgres, pgadmin4 environment construction
React environment construction with Docker
Creating a docker host on AWS using Docker Machine (personal memorandum)
Easy environment construction of MySQL and Redis with Docker and Alfred
Rails + MySQL environment construction with Docker
Node.js environment construction with Docker Compose
Environment construction with Docker for beginners
Laravel + Docker Laradock usage environment construction
Rails on Docker environment construction procedure
A memorandum of personal phpenv install
[Environment construction with Docker] Rails 6 & MySQL 8
Build an environment of "API development + API verification using Swagger UI" with Docker
Create a web environment quickly using Docker
SQL statement learning ~ Environment construction ~ Docker + MySQL
[Processing x Java] Construction of development environment
Launch docker container on EC2 (personal memorandum)
Laravel development environment construction with Docker (Mac)
Sapper × Go (echo) × Docker development environment construction
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Rails API server environment construction using docker-compose
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
Redmine (Scrum, Agile plug-in) environment construction memorandum
Spring Boot + Docker Java development environment construction
Laravel + MySQL + phpMyadmin environment construction with Docker
Docker memorandum
Spring Boot environment construction with Docker (January 2021 version)
Docker + DynamoDB local + C ++ environment construction and practice
Create a Privoxy + Tor environment instantly using Docker
Self-hosting with Docker of AuteMuteUs in Windows environment
Environment construction command memo with Docker on AWS
[Rails] Display of multi-layered data using select boxes
[Ubuntu 18.04] Environment construction for using PyTorch with RTX3090
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Improve the performance of your Docker development environment
Development environment construction using IntelliJ IDEA + Maven + Tomcat 9
[Personal memo] Ruby on Rails environment construction (Windows)
[Note] Struts2 environment construction using Gradle in Eclipse
React + Django + Nginx + MySQL environment construction with Docker
Environment construction method and troubleshooter at the time of joint development (rails, docker and github)
Environment construction of keras and tensorflow, jupyter lab by docker and connection to jupyter by port forwarding
Data management using volume in Docker (personal memorandum)
Construction of data analysis environment using Docker (personal memorandum)
Building a CICD pipeline using Docker (personal memorandum)
Docker Machine (personal memorandum)
Docker network (personal memorandum)
Creating a docker host on AWS using Docker Machine (personal memorandum)
Launch docker container on EC2 (personal memorandum)
Docker Compact Manual (2: Mount and Data Persistence)
Docker memorandum
Docker memorandum
Kaggle environment construction using official Docker and vscode
Django development environment construction using Docker-compose (personal memorandum)