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

相关推荐
小p16 小时前
docker学习: 2. 构建镜像Dockerfile
docker
小p1 天前
docker学习: 1. docker基本使用
docker
蝎子莱莱爱打怪2 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
埃博拉酱2 天前
VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传
windows·ssh·visual studio code
崔小汤呀2 天前
Docker部署Nacos
docker·容器
缓解AI焦虑2 天前
Docker + K8s 部署大模型推理服务:资源划分与多实例调度
docker·容器
唐宋元明清21882 天前
.NET 本地Db数据库-技术方案选型
windows·c#
1candobetter2 天前
Docker Compose Build 与 Up 的区别:什么时候必须重建镜像
docker·容器·eureka
DianSan_ERP2 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
加号32 天前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql