如何在Linux宿主机的Windows 10虚拟机中运行Docker?
Absolutely—Docker works perfectly in your Windows 10 VirtualBox VM. The error you’re seeing is fixable; it usually stems from daemon startup issues, permission problems, or compatibility conflicts between VirtualBox and Docker’s default settings. Let’s walk through the solutions step by step.
1. Hyper-V Conflict with VirtualBox
VirtualBox and Hyper-V are incompatible, and Docker Desktop enables Hyper-V by default when using WSL2. This can break both your VM’s functionality and Docker’s daemon startup. Here’s how to resolve it:
- Open Command Prompt as Administrator in your Windows 10 VM.
- Run this command to disable Hyper-V:
bcdedit /set hypervisorlaunchtype off - Restart your Windows VM.
- Reconfigure Docker Desktop to use Windows containers (not WSL2):
- Open Docker Desktop Settings > General.
- Uncheck "Use the WSL 2 based engine".
- Click "Apply & Restart" to save changes.
2. Ensure the Docker Daemon is Running
The error explicitly calls out that the daemon might not be active. Let’s troubleshoot this:
- Check the Docker service status: Press
Win+R, typeservices.msc, and look for "Docker Desktop Service". If it’s stopped, right-click it and select "Start". - If the service fails to start, check Docker logs for clues: Go to Docker Desktop > Troubleshoot > View Logs. Look for lines referencing startup failures (common issues include corrupted installations or missing dependencies).
- If logs point to corruption, reinstall Docker Desktop: Uninstall it completely, restart the VM, then download the latest stable version and install it (make sure to uncheck WSL2 during setup).
3. Fix Permission Issues
By default, the Docker client needs elevated privileges to connect to the daemon. Try these steps:
- Close all open terminals, then launch PowerShell as Administrator (right-click Start > Windows PowerShell (Admin)).
- Test your
docker buildcommand again in this elevated window. - To avoid needing admin access every time, add your user to the
docker-usersgroup:- Open Computer Management (right-click Start > Computer Management).
- Navigate to Local Users and Groups > Groups > docker-users.
- Add your user account to the group, then restart the VM for changes to take effect.
4. Verify the Docker Connection
After applying the fixes, confirm everything is working:
- Run
docker infoin your terminal. If it returns system details instead of an error, the daemon connection is successful. - Test container functionality with
docker run hello-world—this should pull and run a test container without issues.
If you don’t strictly need Windows-specific .NET Framework features, you could switch to a Linux VM (hosted in VirtualBox) and use Linux containers instead. They’re lighter and often more compatible with .NET Core workflows. But since your project requires .NET Framework, sticking with Windows containers is the right call.
内容的提问来源于stack exchange,提问作者tVoss42

