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 天前
【远程协助】内网 IT 运维远程协助系统的最小可用架构
运维·服务器·远程工作·流媒体·视音频
weixin_462446231 天前
使用 Puppeteer 设置 Cookies 并实现自动化分页操作:前端实战教程
运维·前端·自动化
oMcLin1 天前
如何在 Ubuntu 22.10 上通过 Kubernetes 和 Helm 管理微服务应用,简化跨平台电商平台的自动化部署?
ubuntu·微服务·kubernetes
CheungChunChiu1 天前
Linux 内核动态打印机制详解
android·linux·服务器·前端·ubuntu
oMcLin1 天前
如何在Ubuntu 20.04上配置并优化容器化的SaaS应用平台,实现弹性伸缩与跨区域分布?
ubuntu·sass
实战项目1 天前
软件测试自动化框架的设计与实现
运维·自动化
Aotman_1 天前
Element-UI Message Box弹窗 使用$confirm方法自定义模版内容,修改默认样式
linux·运维·前端
玖釉-1 天前
[Vulkan 学习之路] 08 - 给图片穿马甲:图像视图 (Image Views)
c++·windows·图形渲染
Elastic 中国社区官方博客1 天前
使用 Elastic 中的 OpenTelemetry 为 Nginx 实现端到端分布式追踪的实用指南
大数据·运维·分布式·elasticsearch·搜索引擎·信息可视化·全文检索
独自破碎E1 天前
配置ssh解决https不稳定的问题
运维·ssh