3

I am running Docker Toolkit 1.9.1 on windows 10 64bit, and I am trying to look at the james turnbull book and a simple build up example site.

In a Docker shell, I have created a directory dockerBuilds. In that directory, I created another directory called my-tomcat.

I cd into that directory and run touch Dockerfile. I then created a simple docker build file like this

# start from base image
FROM library/tomcat
MAINTAINER Will Woodman "will.woodman@btinternet.com"

from this I build my image with

docker build -t my-tomcat .

When I start a container with

docker run --name tomcatApp -i -p 8080:8080 my-tomcat

I can see the log trace as tomcat starts up, and when it is settled, connections to http://localhost:8080 fails with Chrome or other browsers.

I stopped and removed the container and then tried:

docker run --name tomcatApp -i -p 127.0.0.1:8080:8080 my-tomcat

and get the same problem.

I even tried to connect to the default docker vm by pointing the browser to http://192.168.99.100:8080, and still can't connect.

So I must be doing something wrong but I don't know what. The logs look fine and the server says it is up. but I'm not seeing any connection when I browse. docker stats tomcatApp shows container is running.

What am I missing here for the port mappings from my windows localhost to the containers ports?

I see this using docker inspect - which looks ok to me

"NetworkSettings": {
     "Bridge": "",
     "SandboxID": "7c58e33e5d3821fc8a1dc6bb6957031d11e07c04bf34f8aa7b17f8afeff03700",
     "HairpinMode": false,
     "LinkLocalIPv6Address": "",
     "LinkLocalIPv6PrefixLen": 0,
     "Ports": {
         "8080/tcp": [
             {
                 "HostIp": "127.0.0.1",
                 "HostPort": "8080"
             }
         ]
     }, 

What am I doing wrong?

Thomasleveil
  • 95,867
  • 15
  • 119
  • 113
WILLIAM WOODMAN
  • 1,185
  • 5
  • 19
  • 36

2 Answers2

2

If you are using docker-machine and try to contact localhost, you would need to add "Port forwarding in docker-machine?"

  • either port forward the 8080port on the VirtualBox level (meaning localhost:8080 will work)

    VBoxManage controlvm "boot2docker-vm" natpf1 "tcp-port5000,tcp,,8080,,8080";
    
  • or use the ip returned by $(docker-machine ip <yourMachine>)

And don't use -p 127.0.0.1:8080:8080, but -p 8080:8080: 127.0.0.1 refers to the localhost of the VirtualBox, not of your host (Windows).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • ok , thanks but i'm still not there yet . i'm still in the docker cmd window on windows - when i try ` VBoxManage ... ` it says command not found, do i have to attch to the container running the tomcat and do this from there - i cant quite see in my head the relationships between the windows machine (primary host ) the virtual box host - running the docker daemon and the container running the tomcat image – WILLIAM WOODMAN Jan 17 '16 at 15:23
  • Check where your VirtualBox is installed, and add that folder to your `%PATH%`. For the relationship, see https://docs.docker.com/engine/installation/windows/#learn-the-key-concepts-before-installing – VonC Jan 17 '16 at 15:25
  • ok - still a dumb-ass but i got enough of a clue to go figure. i added the virtual box install path, but couldnt quite figure out the VBoxmanage controlvm/updatevm correctly - so searched on google and you can set the rule in virtual box by clicking on machine, then networks on RHS, and set the port forward rule on the button there. Given that i'm not that competant yet - driving the ui was a little easier and hides some of the detail from you – WILLIAM WOODMAN Jan 17 '16 at 16:08
  • @WILLIAMWOODMAN yes, that works too. I as I shown here (http://stackoverflow.com/a/33827463/6309), it is `controlvm` if the VM is running, `modifyvm` is the VM is stopped. – VonC Jan 17 '16 at 16:10
  • - any how key point was i now have a rule for http setup and when i do curl on localhost or point my browser at localhost i now get the mapping from my windows 10 through to machine, and can see the response. this will get trickier if i have multiple containers or vms exposing on port 8080. – WILLIAM WOODMAN Jan 17 '16 at 16:13
  • @WILLIAMWOODMAN multiple containers can EXPOSE 8080, but each needs to be *mapped* to a different port in the Linux host (directly accessible using the docker-machine ip command for the right ip) – VonC Jan 17 '16 at 16:14
  • I'm not sure this is the 'best' way to do this as i'm not sure if its all requests, or just when the vm is running. also if there are multiple vms exposing port 8080, i'm not sure how youd disambiguate on the windows 10 browser level – WILLIAM WOODMAN Jan 17 '16 at 16:15
  • 1
    @WILLIAMWOODMAN you disambiguate by using the ip of the virtualbox image, and by using different mapped port per containers. – VonC Jan 17 '16 at 16:15
  • i need to print out and try and read the documentation carefully - but you've been a huge help getting over the first hurdle - thanks for all that – WILLIAM WOODMAN Jan 17 '16 at 16:16
0

Build image and Run container as

$ docker build tomcatApp .
$ docker run -p 8080:8080 -t tomcatApp 

Hit given command to find IP address of docker-machine

$ docker-machine ls

The output will be like :

NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v1.10.3

Now run your application from host machine as : http://192.168.99.100:8080/myapp

Riddhi Gohil
  • 1,758
  • 17
  • 17