windows10 install WSL2, Ubuntu, docker

AI- Deploy ChatLLM through docker development and debugging

Reading time: 10 minutes

The content of this article: Install the ubuntu virtual machine on the window, install docker in the virtual machine, deploy the digital human model through docker, and link to the virtual machine through vscode for development and debugging. After the debugging is completed, it can be directly deployed on the cloud.

What is WSL

WSL2 (Windows Subsystem for Linux) is a function supported by the windows system by default, that is, the Windows Linux subsystem, similar to a Linux virtual machine.

Install WSL2

WSL2 is a virtual machine, and the virtual machine (computer) can install various versions of Linux systems:Unbuntu, Centos, Debian

Installing Ubuntu is very simple:

  1. run as administratorWindows PowerShell
  2. install ubuntu
wsl --install
  1. Enable windows system to set WSL
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  1. restart your computer

  2. Win+q, enter in the system ubuntu, search and open
    insert image description here

  3. After opening, since it is the first startup, you will be prompted to create a login user name and password: what
    I set isname: ifredom password: 123456
    insert image description here

After shutting down, how do I start it up again?

  1. Method 1: Still pass Win+q, enter in the system ubuntu, search and open
  2. Method 2: On the command line, WSLenter

insert image description here


other instructions

# 查看已安装的子系统
wsl -l
# 查看子系统具体的版本号
wsl -l -v
# 设置以后安装Linux系统时,默认启用WSL2
wsl --set-default-version 2
# 查看所有可安装Linux版本列表
wsl.exe -l -o

Windows 10 installs Ubuntu 2 by default, you can also install other versions of WSL

terminal

It is inconvenient and unsightly to use cmd. It is recommended to windows terminal
search in the Microsoft Store windows terminal. It should be noted that after installation, windows terminalthe Chinese name in the system 终端, so you need to enter when searching:终端
insert image description here

Install docker in wsl

The purpose of this step: to link your Ubuntu system on the windows system to facilitate development and debugging in VScode

  1. Docker Desktop WSL 2 on Windows
  2. Getting started with Docker container installation on WSL | Microsoft Learn
# docker 是否安装成功. 打开 ubuntu
docker --version

insert image description here

common command

# 查看所有容器:
docker ps -a
# 查看所有镜像:
docker images

docker installs and uses a mirror. Take nginx as an example:

# 安装 nginx 镜像
docker pull nginx
# 启动 名称为 nginx的容器,容器的镜像为刚下载的 nginx 镜像
docker run --name nginx -p 9696:80 -d nginx
# 谷歌浏览器访问地址:
http://localhost:9696

Vscode remotely connects to the subsystem via SSH

vscode installs 4 plugins:

  1. WSL
  2. Dev Containers
  3. Docker
  4. Remote - SSH

Open Ubuntu and start the ssh service on the Ubuntu system, namely:

sudo apt-get update
sudo apt-get install openssh-server
sudo ps -e |grep ssh# 此步可省略,目的在于查看是否启动ssh服务,终端打印sshd字样说明启动了 
sudo service ssh start

Initialize the public key on the Ubuntu system, namely:

ssh-keygen -t rsa -C "[email protected]"

Then cd ~/.sshunder the folder, write the public key into the authorized key, namely:

# 命令的作用: 将 `id_rsa.pub` 文件中的内容追加到 `authorized_keys` 文件中.
cat id_rsa.pub >> authorized_keys

View the files in the current directory:

ls

Then execute:

# 查看ip
ip addr
# eth0中的ip是你的地址

All the above operations are performed in ubuntu.

In windows, open the vscode editor, vscode 点击左下角, clickconect-to-host
insert image description here

Click add new SSH host, enter username@ip地址, what I input locally is: [email protected], enter the password all the way, check the Linux system, and save it.

Finally successfully run:
![[Pasted image 20230813182817.png]]


Add V to the group: elitepeace37

------ If the article is useful to you, thank you in the upper right corner >>> Like | Favorite<<<

Guess you like

Origin blog.csdn.net/win7583362/article/details/132262825