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安装,试了下,可以安装,但运行报错。

相关推荐
较劲男子汉1 小时前
CANN Runtime零拷贝传输技术源码实战 彻底打通Host与Device的数据传输壁垒
运维·服务器·数据库·cann
wypywyp1 小时前
8. ubuntu 虚拟机 linux 服务器 TCP/IP 概念辨析
linux·服务器·ubuntu
阿蒙Amon1 小时前
TypeScript学习-第10章:模块与命名空间
学习·ubuntu·typescript
风流倜傥唐伯虎2 小时前
Spring Boot Jar包生产级启停脚本
java·运维·spring boot
Doro再努力2 小时前
【Linux操作系统10】Makefile深度解析:从依赖推导到有效编译
android·linux·运维·服务器·编辑器·vim
senijusene2 小时前
Linux软件编程:IO编程,标准IO(1)
linux·运维·服务器
忧郁的橙子.2 小时前
02-本地部署Ollama、Python
linux·运维·服务器
醇氧2 小时前
【linux】查看发行版信息
linux·运维·服务器
lpruoyu2 小时前
【Docker进阶-03】存储原理
docker·容器
No8g攻城狮3 小时前
【Linux】Windows11 安装 WSL2 并运行 Ubuntu 22.04 详细操作步骤
linux·运维·ubuntu