docker install pytorch environment

Basic operation of docker

  1. View currently running docker containers:
sudo docker ps
  1. View all docker containers:
sudo docker ps -a
  1. View the currently created docker:
sudo docker image ls
  1. Create a docker container:
sudo nvidia-docker run -it -v /mnt/sda/speech:/var/workspace --name speech nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04 /bin/bash

insert image description here
The blue font is the name of the created docker container, and the two places must be the same; the red font is the available docker type.
Once created, it will automatically enter the container.

  1. Exit the docker container:
exit

Sometimes the prompt "there are stopped jobs" will appear, then:

jobs -l

View the list of stopped processes (the program or process is suspended due to pressing Ctrl+Z), kill or activate the process:

kill %1
fg %1

The number behind % represents the process number

  1. Enter the docker container
sudo docker start -i ID

7. Due to various reasons, it gets stuck when entering the container

sudo docker restart ID

After restart, start to enter the container

  1. delete docker container
sudo docker rm ID

Note: This command can only be called to clear after exiting successfully in the container.

Install individual packages

  1. update download source
apt-get update
  1. Install Common Toolkit
  • file transfer
apt-get install lrzsz

How to use: rz -bey selects local file upload; sz selects the file on the server to download to the local
Note: rz can only upload files < 4GB, if you want to upload files exceeding 4GB, please refer to
https://blog.csdn.net/ FLawiet/article/details/89597389?spm=1001.2014.3001.5506
PS: Don’t use the rz method to upload files, no matter how you set it, it is easy to garble characters, directly refer to the everything method to upload files.
Try not to use the sz method to download files, it is easy to get stuck or garbled, use the docker cp command to copy to the host first, and then download to the local.

sudo docker cp 容器ID:容器中的文件路径 宿主机的文件路径
  • Text Editor
apt-get install vim
  • Download Document
apt-get install wget
  • git
apt-get install git
  • file decompression
apt-get install unzip
  • YUM RPM package installation management
apt-get install yum

Build the pytorch environment

  1. install python
apt-get install python3.8

Create a soft link for python:

ln -sf /usr/bin/python3.8 /usr/bin/python
  1. install pip
apt install python3-pip
pip3 install --upgrade pip

pip change source:

mkdir ~/pip
vim ~/pip/pip.conf

Enter in the vim editor:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple
[install]
trusted-host=mirrors.aliyun.com

  1. Install anaconda
    to download the installation package and install:
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.11-Linux-x86_64.sh
bash Anaconda3-2021.11-Linux-x86_64.sh

During the installation process, you will be asked if you want conda init, and you must yes
to include conda in the environment variable:

vim ~/.bashrc

Add the path of anaconda at the end of the pop-up file:

export PATH=~/root/anaconda3/bin:$PATH

Activate the environment variable:

source ~/.bashrc
  1. Install pytorch
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch

Verify that the installation was successful:
insert image description here

Other operations and points to note

  1. Operation of conda environment
  • exit conda
conda deactivate
  • View the current conda environment
conda env list
  • Enter the conda environment
conda activate name
  • Create a new conda environment
conda create -n name

Note: It is best to exit the conda environment when using the apt-get install command, otherwise it may prompt that there is insufficient space

  1. screen

This instruction can realize the parallelism of multiple tasks (consider whether the memory and video memory are sufficient), and even if you shut down the server, it is still running.

  • After installing screen
    and exiting the conda environment, enter the command:
apt-get install screen
  • Use screen
    to create a new one:
screen -S name

activation:

screen -d name

Enter:

screen -r name

View all screens:

screen -ls

Exit:
ctrl A+D
to delete the screen image:

kill screen的uid

Guess you like

Origin blog.csdn.net/qq_44445108/article/details/126915729