This guide provides comprehensive instructions for running docker-magento on Windows using WSL2. While docker-magento was primarily designed for Mac and Linux, it can work excellently on Windows with proper configuration.
- Prerequisites
- System Requirements
- Initial Windows & WSL2 Setup
- Docker Desktop Configuration
- Project Setup
- SSL Certificate Configuration
- Performance Optimization
- IDE Configuration
- Common Issues and Solutions
- Best Practices
This guide assumes you:
- Have Docker Desktop installed on Windows
- Know how to install and use WSL2
- Have basic knowledge of Docker
- Are using Windows 10/11 Pro, Enterprise, or Home (with WSL2 support)
- Windows 10: Version 1903 or higher (Build 18362 or higher) for x64 systems
- Windows 10: Version 2004 or higher (Build 19041 or higher) for ARM64 systems
- Windows 11: Any version
- RAM: Minimum 16GB system RAM (32GB recommended)
- CPU: Minimum dual-core (6+ cores recommended)
- Storage: SSD strongly recommended
- Requires Microsoft Windows 10 Professional or Enterprise 64-bit, or Windows 10 Home 64-bit with WSL2
- Docker Desktop 4.x or higher
Open PowerShell as Administrator and run:
# Enable Windows Subsystem for Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# Enable Virtual Machine Platform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# Enable Containers (for Docker)
Enable-WindowsOptionalFeature -Online -FeatureName containers -All
# Enable Hyper-V
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
REBOOT YOUR SYSTEM after running these commands.
After reboot, install the Linux kernel update package:
- For x64 machines: Download x64 WSL2 Kernel
- For ARM64 machines: Download ARM64 WSL2 Kernel
Open PowerShell as Administrator:
wsl --set-default-version 2
Install Ubuntu from the Microsoft Store:
- Ubuntu 22.04 LTS (Recommended)
- Or Ubuntu 20.04 LTS
Install Windows Terminal from the Microsoft Store for a better command-line experience.
Create a .wslconfig
file in your Windows user directory (C:\Users\YourUsername\.wslconfig
):
[wsl2]
memory=16GB
processors=6
swap=2GB
Adjust values based on your system. After creating this file:
- Open PowerShell as Administrator
- Run:
wsl --shutdown
- Wait 8 seconds before starting WSL again
Download and install Docker Desktop for Windows.
- Open Docker Desktop settings
- Go to General and ensure "Use the WSL 2 based engine" is checked
- Go to Resources > WSL Integration:
- Enable integration with your Ubuntu distro
- Check "Enable integration with my default WSL distro"
- Go to Resources > Advanced:
- Memory: Allocate at least 6GB (8GB+ recommended)
- CPUs: Allocate at least 4 CPUs
- Apply & Restart Docker Desktop
Open Windows Terminal, select your Ubuntu profile, and verify Docker is accessible:
docker --version
docker run hello-world
Open Ubuntu terminal and run:
sudo apt update
sudo apt install -y \
curl \
libnss3-tools \
unzip \
rsync \
bc \
jq
CRITICAL: Windows uses CRLF line endings while Linux uses LF. This causes "file not found" errors.
Create a .gitconfig
in your WSL home directory:
nano ~/.gitconfig
Add:
[core]
autocrlf = false
eol = lf
IMPORTANT: Always create projects within the WSL filesystem for performance:
cd ~
mkdir -p Sites/magento
cd Sites/magento
# Download the Docker Compose template
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
# Fix line endings in all bin files
find ./bin -type f -exec sed -i 's/\r$//' {} +
find ./env -type f -exec sed -i 's/\r$//' {} +
bin/download 2.4.8-p1
You need to add entries to both Windows and WSL hosts files.
echo "127.0.0.1 ::1 magento.test" | sudo tee -a /etc/hosts
- Open Notepad as Administrator
- Open
C:\Windows\System32\drivers\etc\hosts
- Add:
127.0.0.1 magento.test
bin/setup magento.test
If you encounter "chmod: cannot access 'bin/magento': No such file or directory":
bin/copytocontainer --all
bin/setup magento.test
SSL certificates require special handling on Windows.
bin/setup-ssl magento.test
Open PowerShell as Administrator:
# Convert PEM to CRT (adjust path to your project)
& 'C:\Program Files\Git\usr\bin\openssl.exe' x509 -outform der -in \\wsl.localhost\Ubuntu\home\yourusername\Sites\magento\rootCA.pem -out rootca.crt
# Import to Windows certificate store
Import-Certificate -FilePath .\rootca.crt -CertStoreLocation Cert:\LocalMachine\Root\
- Restart Chrome: Navigate to
chrome://restart
- The certificate should now be trusted
- Navigate to
about:config
- Set
security.enterprise_roots.enabled
totrue
- Restart Firefox
CRITICAL: Always keep your files in the WSL filesystem (~/Sites/magento
), NOT in Windows directories (/mnt/c/...
). Windows filesystem access from WSL is extremely slow.
Use the Linux-optimized compose file:
cp compose.dev-linux.yaml compose.dev.yaml
Windows Defender can significantly slow down file operations. Add an exclusion:
- Open Windows Security
- Go to Virus & threat protection > Manage settings
- Add exclusion for:
\\wsl.localhost\Ubuntu\home\yourusername\Sites
Add to your WSL ~/.bashrc
:
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
In PhpStorm, open project from:
\\wsl.localhost\Ubuntu\home\yourusername\Sites\magento
Or use WSL path:
\\wsl$\Ubuntu\home\yourusername\Sites\magento
- Go to File > Settings > PHP
- Click "..." next to CLI Interpreter
- Add new interpreter: From Docker, Vagrant, VM...
- Select Docker Compose
- Configuration:
- Server: Docker
- Configuration files: Select both
compose.yaml
andcompose.dev.yaml
- Service:
phpfpm
- Name it "Docker PHP" and apply
- Go to File > Settings > Build, Execution, Deployment > Deployment
- Add new deployment configuration (Type: SFTP)
- Connection settings:
- SFTP host:
localhost
- Port:
22
- User name:
app
- Password:
app
- Root path:
/var/www/html
- SFTP host:
- Mappings tab:
- Local path: Your project root
- Deployment path:
/
- Install Xdebug Helper for Chrome
- In Chrome extension options, set IDE key to
PHPSTORM
- Enable Xdebug in container:
bin/xdebug enable
- In PhpStorm, go to File > Settings > PHP > Debug:
- Debug port:
9000,9003
- Debug port:
- Create a server in PHP > Servers:
- Name:
magento.test
- Host:
magento.test
- Port:
80
- Debugger: Xdebug
- Use path mappings: Check and map
src
to/var/www/html
- Name:
Go to File > Settings > PHP > Quality Tools:
For each tool (PHP_CodeSniffer, Mess Detector, etc.):
- Click "..." next to Configuration
- Select "By Docker Interpreter"
- Choose your Docker interpreter
- Set paths (replace
yourusername
):- PHP_CodeSniffer:
/home/yourusername/Sites/magento/src/vendor/bin/phpcs
- PHP CS Fixer:
/home/yourusername/Sites/magento/src/vendor/bin/php-cs-fixer
- Mess Detector:
/home/yourusername/Sites/magento/src/vendor/bin/phpmd
- PHP_CodeSniffer:
Install the "WSL" extension in VS Code.
- Open VS Code
- Press
Ctrl+Shift+P
- Run "WSL: Connect to WSL"
- Open folder:
~/Sites/magento
- Install "PHP Debug" extension by Felix Becker
- Create
.vscode/launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceFolder}/src"
},
"hostname": "localhost"
}
]
}
bin/xdebug enable
Open PowerShell as Administrator:
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
Even with .wslconfig
, this check might fail. The check is in bin/download
. If you've properly configured Docker resources, you can comment out the memory check temporarily.
If you get 403 errors when accessing the site:
# Fix permissions
bin/fixowns
bin/fixperms
# Restart containers
bin/restart
This is almost always a line endings issue:
# Fix line endings for all shell scripts
find ./bin -type f -exec dos2unix {} \;
# Or if dos2unix is not installed:
find ./bin -type f -exec sed -i 's/\r$//' {} +
Ensure you're:
- Using the WSL filesystem (not /mnt/c/)
- Have adequate resources allocated in
.wslconfig
- Have excluded WSL paths from Windows Defender
- Not syncing large directories like
vendor/
orgenerated/
from Windows
If you encounter network issues:
# Disable IPv6 if causing issues
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
# Set DNS servers
echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf
echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf
If Windows paths interfere with WSL:
Create /etc/wsl.conf
in WSL:
sudo nano /etc/wsl.conf
Add:
[interop]
appendWindowsPath = false
Then restart WSL:
wsl --shutdown
WSL clock can drift, affecting SSL:
sudo hwclock -s
- ALWAYS use WSL filesystem for projects
- Access from Windows via
\\wsl.localhost\Ubuntu\home\username\Sites
- Never use
/mnt/c/
for project files
- Configure Git in WSL, not Windows
- Use SSH keys generated in WSL
- Set proper line endings in
.gitconfig
- Keep Docker Desktop updated
- Regularly update WSL:
wsl --update
- Monitor disk usage:
docker system df
- Clean up periodically:
docker system prune -a
- Use Windows tools to backup WSL files via
\\wsl.localhost\
- Consider using
wsl --export
for full WSL backups
- Use Windows Terminal with Ubuntu profile
- Avoid mixing Windows and WSL commands
- Run all docker-magento commands from WSL
After completing setup:
- Access Magento at: https://magento.test
- Admin panel: https://magento.test/admin
- Username:
john.smith
- Password:
password123
- Username:
- Mailcatcher: http://magento.test:1080
- PhpMyAdmin: http://localhost:8080
If something isn't working:
- Are you in WSL Ubuntu terminal (not Windows)?
- Are files in WSL filesystem (not
/mnt/c/
)? - Did you fix line endings in
bin/
files? - Is Docker Desktop running with WSL2 integration?
- Did you add hosts entries to both Windows and WSL?
- Did you allocate enough resources in
.wslconfig
? - Have you restarted WSL after configuration changes?
- Are you using the correct URL (https://magento.test)?
Remember: Most issues on Windows stem from line endings, file permissions, or using Windows filesystem instead of WSL filesystem.