Docker部署Magento 2后无法访问https://magento2.test,寻求本地访问指引
https://magento2.test Access Issues with Mark Shust's Docker Magento Setup Hey there! I’ve walked through this exact setup dozens of times, so let’s break down the most common fixes to get your local Magento 2 instance up and accessible:
1. Verify Your Local Hosts File Entry
First, your system needs to know where to route magento2.test—this is handled by the hosts file.
- On macOS/Linux: Open a terminal and run
sudo nano /etc/hosts. Add this line at the bottom:
Save with127.0.0.1 magento2.testCtrl+O, exit withCtrl+X. - On Windows: Open Notepad as Administrator, then open
C:\Windows\System32\drivers\etc\hosts. Add the same line above, then save.
2. Check if Docker Containers Are Running
If your containers aren’t active, nothing will respond. Run this command in your project directory:
docker-compose ps
Look for all core services (web, db, php-fpm, etc.) to show a status of Up. If any are Exited or Restarting, restart them with:
docker-compose up -d
You can also check web container logs for critical errors like port conflicts:
docker-compose logs web
3. Confirm Port Mapping & Availability
The default setup uses ports 80 (HTTP) and 443 (HTTPS). If another service (like Apache, Nginx, or even a messaging app) is using these ports, Docker can’t bind to them.
- Check your
docker-compose.ymlfor the web service’s port section. It should look something like:ports: - "80:80" - "443:443" - If ports are occupied, modify the mappings (e.g.,
"8080:80"and"8443:443"), restart containers, then visithttps://magento2.test:8443instead.
4. Trust the Local SSL Certificate
Browsers often block untrusted SSL certificates, which can manifest as a "page not found" error instead of a clear certificate warning.
- Locate the generated certificate in your project’s
ssldirectory (usuallymagento2.test.crt). - macOS: Double-click the certificate, open "Keychain Access", find the certificate, right-click it, and select "Get Info" > "Trust" > "Always Trust".
- Windows: Right-click the certificate, choose "Install Certificate", select "Local Machine", then "Place all certificates in the following store" > "Trusted Root Certification Authorities".
- Linux: Copy the certificate to
/usr/local/share/ca-certificates/, then runsudo update-ca-certificates.
5. Test Inside the Docker Web Container
To rule out local network issues, jump into the web container and test access internally:
docker-compose exec web bash
Once inside, run:
curl https://magento2.test
If you see Magento’s HTML output, the container is working fine—your issue is with local DNS, certificates, or port forwarding.
6. Flush DNS & Browser Caches
Old cached DNS records or browser data can block access:
- Browser: Open an incognito/private window and try accessing the URL again, or clear your cache with
Ctrl+Shift+Delete. - Local DNS:
- macOS:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder - Windows:
ipconfig /flushdns - Linux:
sudo systemctl restart systemd-resolved(adjust for your distro if needed)
- macOS:
内容的提问来源于stack exchange,提问作者LuDev

