如何在Windows Ubuntu应用中运行Docker?报错问题及方案咨询
Hey there! Let me break this down for you step by step since I've dealt with both WSL Docker setups and that annoying Toolbox error before.
First off, forget trying to use Docker Toolbox with WSL—it's built for older Windows versions without Hyper-V, and WSL 2 has a far smoother workflow. Here's the right way:
- Check WSL version: Make sure you're on WSL 2 (WSL 1 doesn't support Docker daemon natively). Run this in PowerShell or Command Prompt:
If your Ubuntu distro shows version 1, upgrade it with:wsl --list --verbose
(Replacewsl --set-version Ubuntu-20.04 2Ubuntu-20.04with your actual Ubuntu version name) - Option 1 (Recommended): Use Docker Desktop
- Install Docker Desktop for Windows, then go to Settings > General and check "Use the WSL 2 based engine".
- Next, head to Settings > Resources > WSL Integration and enable integration for your Ubuntu distro.
- Now open your Ubuntu terminal and run
docker run hello-world—it should work immediately, no extra setup needed. Docker Desktop handles syncing the daemon between Windows and WSL.
- Option 2 (Manual WSL-only setup): If you don't want Docker Desktop, you can install Docker directly in WSL 2:
- Update your package lists:
sudo apt update && sudo apt install docker.io - Start the Docker daemon:
sudo systemctl start docker - Enable auto-start on boot:
sudo systemctl enable docker - Add your user to the
dockergroup so you don't needsudoevery time:sudo usermod -aG docker $USER - Log out and back in, then verify with
docker run hello-world.
- Update your package lists:
That error pops up because Docker Toolbox runs the daemon inside a VirtualBox VM (usually named default), not directly on your system. Here's how to fix it:
- First, check if the VM is running: Open the Docker Quickstart Terminal—if it fails to start the VM, run this in Git Bash (Toolbox uses Git Bash by default):
docker-machine start default - Then, set the required environment variables to point your terminal to the VM's daemon:
eval $(docker-machine env default) - Now try running a Docker command again—it should connect properly.
If you still run into issues, it's probably because Toolbox and WSL are conflicting. Toolbox is really only useful if you're on Windows 10 Home (which doesn't support Hyper-V) or an older Windows version. For most modern setups, Docker Desktop + WSL 2 is way more reliable.
Let's break down the use cases:
- WSL 2 + Docker Desktop: My go-to recommendation for 90% of developers. Reasons:
- Near-native Linux performance for containers (WSL 2 uses a real Linux kernel under the hood)
- Seamless integration between Windows and Linux—you can edit code in Windows IDEs and run Docker commands in WSL terminals
- Supports all Docker features, including Docker Compose, Kubernetes, and multi-arch builds
- No need to switch between environments; you get the best of both worlds
- Windows Native Docker: Ideal if you're working exclusively with Windows containers (e.g., .NET Framework apps, legacy Windows services). It runs containers directly on Windows without a Linux layer, so it's optimized for Windows workloads.
- Docker Toolbox: Only use this if you're stuck on an older Windows version (pre-Windows 10 1903) or Windows 10 Home without Hyper-V support. It's outdated compared to Docker Desktop + WSL 2.
内容的提问来源于stack exchange,提问作者Freid001




