Docker, Windows y la falta de espacio en disco

Guía práctica para liberar espacio en AppData al usar Docker Desktop con WSL 2 en Windows: aprende a compactar archivos VHDX con Optimize-VHD o diskpart y recuperar gigas sin interrumpir tus contenedores

16 sept 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Honestamente me encanta Docker. Atrás quedaron los días de XAMPP y de instalar dependencias en la máquina anfitriona. En mi flujo diario funciona mucho mejor que Vagrant. A pesar de ser fan de Linux, trabajo con Windows y uso Docker Desktop en el host con WSL 2 y Ubuntu 24 para ejecutar mis contenedores, y en general va muy bien.

El detalle molesto es que WSL y Docker Desktop no guardan los archivos directamente en NTFS sino dentro de enormes discos virtuales vhdx. Cuando borras datos dentro de Ubuntu o de Docker el espacio queda libre dentro de ext4 pero el archivo vhdx no se reduce; solo crece. Con el tiempo eso se traduce en cientos de gigas ocupando AppData.

La solución es compactar los archivos VHDX después de apagar WSL y Docker Desktop usando Optimize-VHD o diskpart. Ese proceso recupera bloques no usados y reduce el tamaño físico del archivo. Si se te olvida hacerlo de vez en cuando como me pasa a mí, puedes inspeccionar rápidamente cuánto ocupa con este one liner de PowerShell: @(Get-ChildItem $env:LOCALAPPDATA\Docker\wsl -Filter *.vhdx -Recurse -ErrorAction SilentlyContinue; Get-ChildItem $env:LOCALAPPDATA\Packages\*\LocalState\ext4.vhdx -File -ErrorAction SilentlyContinue) | Select-Object FullName,@{n=SizeGB;e={[math]::Round($_.Length/1GB,2)}} | Sort-Object SizeGB -Descending

Para liberar espacio de forma segura sigue estos pasos generales en una terminal de PowerShell elevada: 1 Apagar WSL con wsl --shutdown. 2 Cerrar Docker Desktop. 3 Localizar los archivos vhdx en las rutas habituales dentro de AppData. 4 Intentar compactar con el módulo Hyper V Optimize VHD si está disponible. 5 Si no hay módulo Hyper V usar diskpart con los comandos select vdisk file y compact vdisk. 6 Volver a comprobar tamaños para confirmar la ganancia de espacio. Si necesitas puedes hacer antes una limpieza de Docker con docker system prune y eliminar volúmenes e imágenes no usados, pero si necesitas espacio de forma urgente puedes compactar sin tocar contenedores en uso.

Advertencia importante no ejecutes comandos copiados de internet sin entenderlos. El procedimiento descrito parará WSL y Docker Desktop, buscará los vhdx en rutas comunes, mostrará el tamaño actual, intentará redimensionar cada disco con Hyper V y si no está disponible usará diskpart, y al final volverá a evaluar los archivos para mostrar cuánto espacio se ha recuperado.

En Q2BSTUDIO somos una empresa de desarrollo de software especializada en aplicaciones a medida y software a medida, con experiencia en inteligencia artificial, ciberseguridad, servicios cloud aws y azure y servicios inteligencia de negocio. Si necesitas soluciones personalizadas para tu infraestructura o quieres asesoramiento para optimizar despliegues en la nube y contenedores podemos ayudarte. Conoce nuestro trabajo en desarrollo de aplicaciones y software a medida y descubre nuestras opciones de servicios cloud AWS y Azure para migraciones, backups y optimización de costes.

Integramos inteligencia artificial e ia para empresas, desarrollamos agentes IA y soluciones con power bi para servicios inteligencia de negocio, y ofrecemos auditorías de ciberseguridad y pentesting para proteger tus activos. Si te quedas sin espacio por vhdx o necesitas una arquitectura más eficiente contacta con nosotros y te ayudamos a diseñar una solución a medida.

Por mi parte sigo echando de menos trabajar en Linux y coincidir con herramientas nativas, pero con las prácticas correctas de compactación y monitorización se puede mantener Windows con WSL y Docker sin que AppData devore el disco.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat