Boot2Docker - access to the web server as a local host

Created the apache web server as a Docker container, but wants to access it in the windows os browser as localhost.

I can access the web server with the private IP address of boot2docker, which is 192.168.59.103, but would like to access the web server as localhost ie 127.0.0.1.

Below is the setup of my Docker Container

Running Boot2docker on Oracle VM Open Ports: "EXPOSE 80 443" in Docker File

The command used to create the Docker file:

docker run --net=host --name=webserver1 -v /home/data:/data/www/www.samplewebserber.com -v `password`:/scripts -d folder/serverfolder /scripts/run.sh 
+8
docker boot2docker portforwarding
source share
2 answers

If you want to access localhost on ports 80 and 443, you need to do two things:

  • First, when you create your container, you must specify a specific port mapping. If you run docker run with the -P option, the ports installed in the dockerfile EXPOSE file will map to random ports in the Boot2Docker environment. If you want to display it, you must run:

     docker run \ --net=host \ --name=webserver1 \ -v /home/data:/data/www/www.samplewebserber.com \ -v `password`:/scripts \ -d -p 80:80 -p 443:443 \ folder/serverfolder \ /scripts/run.sh 
  • And in order to map the Boot2Docker port to your host environment, as the link to Joe Niland suggested, you must perform port forwarding using SSH tunneling:

    boot2docker ssh -L 80:localhost:80

    boot2docker ssh -L 443:localhost:443

You can change the port mapping if you want.

+5
source share

boot2docker actually created a linux kernel vm on your Mac OS with VirtualBox, and 192.168.59.103 is the ip for this vm.

So you need to set the port forward for this vm

Note that on Mac OS, port 80 requires high resolution, so instead I use 8080 in this example.

enter image description here

+15
source share

All Articles