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.
-#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
By adding a path to the environment variable $ PATH, the computer will search for the program from that path.
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
-#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".
-#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.
-# 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.
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=''" ]
% 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.
-#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