window10的wsl安装配置ubuntu22.04和docker

1.安装ubuntu

管理员身份运行命令行

查询可使用的linux版本

bash 复制代码
wsl --list --online

网速好下载发布版:

bash 复制代码
wsl --install -d Ubuntu-22.04

网速不好下载网络版,然后重启:

bash 复制代码
wsl --install --web-download -d Ubuntu-22.04

下载安装好后,可通过开始菜单打开

打开后设置用户名和密码,界面如下:

若忘记ubuntu密码:

bash 复制代码
# 管理员身份运行 PowerShell
wsl --user root
passwd root

2.配置ubuntu

ubuntu后续需要安装很多东西,使用ubuntu自带的镜像,国内有点慢,故需改镜像。

备份:

bash 复制代码
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

修改:

bash 复制代码
sudo vim /etc/apt/sources.list

#原镜像:http://archive.ubuntu.com/ubuntu/
#新镜像:http://mirrors.aliyun.com/ubuntu/

更新:

bash 复制代码
sudo apt update && sudo apt upgrade

3.安装docker

ubuntu作为服务器后台程序,目前使用较多的是docker,故需进行安装:

安装:

bash 复制代码
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo apt-get install --only-upgrade openssl
sudo apt-get update
sudo apt-get install --reinstall ca-certificates
sudo update-ca-certificates
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

验证:

4.配置docker

后续需要使用docker进行下载容器,原有的镜像有点慢,需要更换

配置:

bash 复制代码
sudo vim /etc/docker/daemon.json
javascript 复制代码
{
  "registry-mirrors": [
    "https://docker.1panel.live",
    "https://hub.rat.dev",
    "https://docker.actima.top"
  ]
}

重启:

bash 复制代码
# 重启
sudo systemctl daemon-reload
sudo systemctl restart docker

其他:

bash 复制代码
# 关闭docker服务
sudo systemctl stop docker.socket
sudo systemctl stop docker.service

#查询
sudo systemctl status docker

5.使用docker

下载镜像:

bash 复制代码
# 有Dockerfile文件
docker build . --network=host -t 镜像名

# 无Dockerfile文件
docker pull 镜像名

# python为例
docker pull python:3.11

运行镜像:

bash 复制代码
docker run -it --network=host -v 主机路径:容器路径 镜像名

其他:

bash 复制代码
# 查看容器
docker ps

# 查询镜像
docker images 

# 退出
exit

6.文件传输

更多时候需要实现windows和ubuntu文件互传

可以使用ssh(ubuntu服务端)+FileZilla(windows客户端)实现

ubuntu:

bash 复制代码
# 查看ssh,没有装
ssh localhost
ps -e | grep ssh
sudo apt update
sudo apt install openssh-server

# 查看IP地址,没有装
ifconfig
sudo apt install net-tools

windows:

bash 复制代码
# 下载免安装即可
# https://www.filezilla.cn/download/client

# 配置(ubuntu地址,用户名,密码,端口默认22)

7.总结

相比原来需要通过虚拟机安装linux系统,win10之后的wsl要方便很多。

网上也有很多小伙伴使用Microsoft Store安装,试了下,可以安装,但运行报错。

相关推荐
陈桴浮海8 分钟前
Kustomize实战:从0到1实现K8s多环境配置管理与资源部署
云原生·容器·kubernetes
獨枭27 分钟前
Windows 下安装与使用 Miniconda 完整指南
windows
珠海西格电力科技1 小时前
微电网能量平衡理论的实现条件在不同场景下有哪些差异?
运维·服务器·网络·人工智能·云计算·智慧城市
释怀不想释怀1 小时前
Linux环境变量
linux·运维·服务器
zzzsde1 小时前
【Linux】进程(4):进程优先级&&调度队列
linux·运维·服务器
命里有定数2 小时前
保姆级教程:在 Windows (WSL2) 下本地部署 Qwen3-ASR
windows
神筆&『馬良』2 小时前
Foundation_pose在自己的物体上复现指南:实现任意物体6D位姿检测(利用realsense_D435i和iphone_16pro手机)
目标检测·ubuntu·机器人·视觉检测
70asunflower2 小时前
Emulation,Simulation,Virtualization,Imitation 的区别?
linux·docker
聆风吟º3 小时前
CANN开源项目实战指南:使用oam-tools构建自动化故障诊断与运维可观测性体系
运维·开源·自动化·cann
ShiLiu_mtx3 小时前
k8s - 7
云原生·容器·kubernetes