Windows11下清理Docker Desktop与wsl的C盘空间占用

31 篇文章 0 订阅
13 篇文章 0 订阅

xshell连接Windows中通过wsl安装的linux子系统-Ubuntu 22.04

一、清理Docker Desktop的磁盘占用

前提:首先启动Windows上的Docker Desktop

//【查看docker 占用的空间】
docker system df


TYPE 列出了docker 使用磁盘的 4 种类型:
Images:所有镜像占用的空间,包括拉取下来的镜像,和本地构建的。

Containers:运行的容器占用的空间,表示每个容器的读写层的空间。

Local Volumes:容器挂载本地数据卷的空间。

Build Cache:镜像构建过程中产生的缓存空间(只有在使用 BuildKit 时才有,Docker 18.09 以后可用)。

RECLAIMABLE :可回收大小。


//【镜像的磁盘占用】
//列出所有悬挂状态的镜像:docker image ls -f dangling=true
//1-删除镜像
docker image prune  或者 docker image rm $(docker image ls -f dangling=true -q)

                     

//【数据卷的磁盘占用】
//2-删除不再使用的数据卷
docker volume prune   或者   docker volume rm $(docker volume ls -q)


//【Build Cache 的磁盘占用】
//3-删除 build cache磁盘占用
docker builder prune  


//【4-一键清理】
docker system prune

在这里插入图片描述

二、清理wsl的磁盘占用

//1-可以先使用命令行来检查它的状态:
wsl -l -v
 或者 
wsl --list -v 
 或者 
wsl.exe --list --verbose 


//2-如果状态是 Running,再用命令行去关闭:
wsl.exe --terminate 名称
例如:
wsl.exe --terminate Ubuntu-22.04   
wsl.exe --terminate docker-desktop   
wsl.exe --terminate docker-desktop-data   

//3-关闭所有 WSL 实例
wsl.exe --shutdown

//4-使用diskpart工具压缩虚拟磁盘文件
//4-1
找到你的wsl虚拟磁盘位置,我这里是
C:\Users\JIACHENGER\AppData\Local\Docker\wsl\data\DockerDesktopWSL\data\ext4.vhdx
和
C:\Users\JIACHENGER\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx

//4-2
在PowerShell中,输入diskpart命令,启动diskpart工具。

//4-3 依次输入下列命令
//选择目标磁盘文件
select vdisk file="C:\Users\JIACHENGER\AppData\Local\Docker\wsl\data\DockerDesktopWSL\data\ext4.vhdx"

select vdisk file="C:\Users\JIACHENGER\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx"
//以只读模式连接虚拟磁盘文件
attach vdisk readonly

//开始压缩虚拟磁盘文件
compact vdisk

//分离虚拟磁盘文件
detach vdisk

//退出diskpart工具
exit

1-可以先使用命令行来检查它的状态
在这里插入图片描述
2-如果状态是 Running,再用命令行去关闭
在这里插入图片描述
使用diskpart工具压缩虚拟磁盘文件
在这里插入图片描述

三、参考资料

如何管理 WSL 磁盘空间
如何使用 WSL 在 Windows 上安装 Linux
WSL 的基本命令

  • 6
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Docker Desktop with WSL (Windows Subsystem for Linux) allows you to run Docker containers on Windows using a Linux distribution. By integrating Docker with WSL, you can leverage the benefits of both Docker and WSL to develop and run containerized applications on your Windows machine. To get started with Docker Desktop and WSL, you need to follow these steps: 1. Install Docker Desktop: Download and install Docker Desktop for Windows from the Docker website. Make sure to enable the WSL 2 backend during installation. 2. Enable WSL: Open PowerShell as an administrator and run the following command to enable WSL: ``` wsl --install ``` This command will install WSL and Linux kernel updates on your Windows machine. 3. Choose a Linux distribution: Open the Microsoft Store, search for your preferred Linux distribution (e.g., Ubuntu, Debian), and install it. This distribution will be used by Docker to run containers. 4. Set WSL version: Open PowerShell as an administrator and run the following command to set WSL version 2 as default: ``` wsl --set-default-version 2 ``` 5. Configure Docker to use WSL: Open Docker Desktop, go to "Settings," select "General," and check the "Use the WSL 2 based engine" option. Then, select the WSL default distribution you installed in step 3. 6. Test Docker: Open a terminal (WSL) and run the following command to verify that Docker is working: ``` docker run hello-world ``` If everything is set up correctly, you should see a "Hello from Docker!" message. That's it! Now you can start running Docker containers using the Linux distribution installed through WSL. Remember that you can also access files and directories on your Windows machine from within the Linux environment to build and run your containerized applications.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值