I have been creating a webserver as Docker container and trying to access it outside the container. But I can't. What I am doing is.
-Pulling a ubuntu image:
docker pull ubuntu:14.04
-Starting a container:
docker -t -i -p 49200:2375 [image-id]
and after installing apache2 in newly started container I can ping the apache2 server inside container, I can also do curl and see results in container terminal, but no luck outside on host machine. I have tried many times. (I am using Virtual Box on windows)
Screen shots:
Questions:
- Am I using right docker commands and port numbers to create container.
- Is there anything wrong in apache configuration. (I am using apache in default mode without any configurations)
- Is there anything wrong with ports on my virtual box or on my pc. I have very low knowledge of networking.
Can someone help!!!
Problem 1: Apache default port
2375
port is not the apache default port, it is the docker daemon default port, the command shall beProblem 2: port in different machine
49200:80
This is the mapping from internal port80
to docker host49200
, the docker host is actually your virtual box VM (guess is your boot2docker shell)In your virtual box VM console, you can
The picture "Port Forwarding rules" are helping your port forward to your virtualbox host, for you it is MacOS, where you mapped
49200
to MacOS49200
as wellSo in your MacOS shell console, you can also
If you know the virtualbox VM (docker host) IP address, for example it is
192.168.59.103
as default for boot2docker, then you canIf you want to access the apache docker container via
172.17.0.7
, remember this is the private network inside, you need to start another container likeSummary
docker -p
is port forwarding your internal port to docker host "Port forwarding Rules" in virtualbox setting is port forwarding your VM port to VM host