如何从Docker容器访问WAMP虚拟主机地址(如http://ebwp.test)?
http://ebwp.test from a Docker Container Got it, let's get your Docker container talking to your WAMP virtual host http://ebwp.test — here's how to make that happen smoothly:
Step 1: Confirm Local Setup First
First, double-check that your local machine's hosts file has this entry (WAMP usually adds this automatically when you create a virtual host, but it's worth verifying):
127.0.0.1 ebwp.test
Also, make sure your WAMP Apache config isn't blocking Docker access. If you see Require local in the <Directory> block of your ebwp.test virtual host config, update it to allow Docker's network range (or open it temporarily for testing):
# Option 1: Open access for testing (not ideal for production) Require all granted # Option 2: More secure — allow only local and Docker subnets Require ip 127.0.0.1 172.17.0.0/16 192.168.0.0/16
Restart WAMP Apache after making this change.
Step 2: Map the Virtual Host to Your Host in Docker
You have two solid options here depending on your needs:
Option A: Temporary Fix (Per Container)
When starting your Docker container, use the --add-host flag to map ebwp.test to your host machine's gateway IP. Docker's built-in host-gateway variable handles this automatically, so no need to hardcode IPs:
docker run --add-host ebwp.test:host-gateway your-image-name
This works right away, but you'll need to include this flag every time you start the container.
Option B: Permanent Fix (All Containers)
If you want every new Docker container to resolve ebwp.test to your host automatically, edit Docker's daemon config:
- Find the
daemon.jsonfile:- Windows:
C:\ProgramData\Docker\config\daemon.json - macOS:
~/.docker/daemon.json - Linux:
/etc/docker/daemon.json
- Windows:
- Create the file if it doesn't exist, then add this content:
{ "extra_hosts": ["ebwp.test:host-gateway"] } - Restart Docker to apply the changes.
Step 3: Test the Connection
Fire up your container, then run a quick test command like:
curl http://ebwp.test
Or if your container has a browser, navigate to http://ebwp.test — you should see your WAMP virtual host site load up successfully!
内容的提问来源于stack exchange,提问作者Lakshmanan Here

