Docker Toolbox Tomcat service can't access from host machine

I uses Docker on window 8.1, Virtual Box 5.0.9 r103669 (with boot2docker) and Docker Toolbox. The container is running (checked with “docker ps”), and also the tomcat server. There is also port forwarding setting on VirtualBox (add or remove doesn’t matter). But when host OS browser browses the server, connection timeout error occurs. I’ve already check with Firewall turned on/off. But still not ok. But on Ubuntu 14.04 environment, it is quite ok, speedy response. Pls help somebody. I m in great hurry… Thanks.

  • I build image as “docker build --rm=true -t imageName .”

  • and run image as “docker run --rm=true -t -i --name containerName imageName /usr/bin/sudo -u win /usr/share/tomcat7/bin/catalina.sh run”… Btw… the run command is not working on quick terminal, so I just write down to Virual box default machine

  • Here is my Dockerfile
    "
    FROM centos

MAINTAINER Win Min Tun

RUN yum -y install sudo

ADD jdk-7u79-linux-x64.tar.gz /opt
WORKDIR /opt/jdk1.7.0_79
RUN alternatives --install /usr/bin/java java /opt/jdk1.7.0_79/bin/java 1
RUN alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_79/bin/jar 1
RUN alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_79/bin/javac 1
RUN echo “JAVA_HOME=/opt/jdk1.7.0_79” >> /etc/environment

ADD apache-tomcat-7.0.65.tar.gz /usr/share
WORKDIR /usr/share/
RUN mv apache-tomcat-7.0.65 tomcat7
RUN echo “JAVA_HOME=/opt/jdk1.7.0_79/” >> /etc/default/tomcat7
RUN groupadd tomcat
RUN useradd -s /bin/bash -g tomcat win
RUN chown -Rf win.tomcat /usr/share/tomcat7

EXPOSE 8080
"

Hi,

In the docker run command you havent exposed port. You should expose the port for you to access it from the host.

Eg:

docker run -it --rm -p 8080:8080 mytomcat

# ie -p <hostport>:<containerport>

After using this you can access the ui, using boot2docker’s ip and hostport which you have exposed.

Regards

1 Like

Hi @ranjandas

Yup it helps! Thanks a lot for this. I now understand the problem. In Ubuntu I don’t need port forwarding -p becuz docker host is the host Ubuntu itself and containers are exposed to host Ubuntu, that s why I can just use each container IP and container port to access. But in Windows, docker host is in Virtual Machine running Boot2Docker and containers are resides in that VM. That’s why in Windows, I have to use VM IP and port forwarding to reach to each container. But I m not sure what if I want more than one container to listen to the same port and in boot2docker it will be a problem.

https://docs.docker.com/engine/installation/windows/

In my case, I do expose the port but still cannot access on Windows 7, have to investigate if this is a firewall issue: