0

This is not the same question as: how do I access a mysql database running in a docker container? I have a spring boot app running in a tomcat in a container, built from the official tomcat image.

Dockerfile

FROM tomcat:latest
RUN rm -f -R $CATALINA_HOME/webapps/ROOT
COPY build/libs/web-1.0-SNAPSHOT.war $CATALINA_HOME/webapps/web.war
COPY context.xml $CATALINA_HOME/conf/context.xml

When I want to run the docker container, I say:

docker build .
#it prints out the newly generated container image id such as 08fc6cbf7759
docker run -p 8888:8080 08fc6cbf7759

Then i get a bunch of stack traces related to the db not receiving any packets:

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:304)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:224)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1012)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:981)

If I drop the WAR file into my locally running tomcat instead of running the docker image, it deploy fine, no DB connection issues. So I know there has to be something to docker that's restricting its ability to contact anything on the outside.

Calicoder
  • 1,322
  • 1
  • 19
  • 37
  • Duplicate of https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach. Should be exactly your case. – wwerner Nov 22 '18 at 17:58
  • Possible duplicate of [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – David Maze Nov 22 '18 at 18:29

0 Answers0