如何在Docker for Windows(Windows10+Hyper-V)上升级docker-compose?
Hey there! Let's get that docker-compose upgrade sorted out for you. The error you're hitting is because your current docker-compose version (1.20.1) uses an API version that's too old for your Docker setup—your compose file's version: '2' requires a newer API level. Here are the most reliable methods to upgrade, tailored to your Windows 10 + Hyper-V + Docker for Windows environment:
Method 1: Upgrade Docker Desktop (Recommended)
Docker for Windows (now called Docker Desktop) bundles docker-compose with it, so upgrading the entire app is the easiest way to get a compatible, up-to-date compose version:
- Right-click the Docker icon in your system tray and select Settings
- Go to the Software Updates tab
- Click Check for updates—if an update is available, follow the prompts to install it
- Once done, restart Docker Desktop, then open PowerShell/Command Prompt and run
docker-compose --versionto confirm the upgrade worked
Method 2: Manually Replace the Docker Compose Binary
If you don't want to upgrade the whole Docker Desktop app, you can manually swap out the compose executable:
- Open PowerShell as an administrator
- First, stop the Docker service to avoid conflicts:
Stop-Service Docker - Download the latest stable docker-compose binary for Windows from Docker's official releases page, then save it to
C:\Program Files\Docker\Docker\resources\bin\docker-compose.exe(replacing the existing file)
Note: The pathC:\Program Files\Docker\Docker\resources\bin\is the default install location for Docker for Windows. If you installed Docker elsewhere, adjust this path accordingly. - Start the Docker service back up:
Start-Service Docker - Verify the upgrade by running:
docker-compose --version
Method 3: Use Chocolatey Package Manager (If You Have It Installed)
If you use Chocolatey to manage Windows software, upgrading is just a quick command:
- Open PowerShell as an administrator
- Run the upgrade command:
choco upgrade docker-compose -y - After the upgrade finishes, restart your terminal and run
docker-compose --versionto check the new version
Quick note: These methods are for the Hyper-V version of Docker for Windows. If you were using Docker Toolbox, the steps would be different—but since you specified Hyper-V, these should work perfectly.
Once you've upgraded, try running docker-compose up with your YAML file again, and that API version error should be gone. If you still run into issues, double-check your Docker engine version with docker version—sometimes upgrading Docker Desktop is necessary to get both the engine and compose in sync.
内容的提问来源于stack exchange,提问作者Rolf




