How to access a MySQL database on the same host from within a docker container?
up vote
0
down vote
favorite
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.
mysql docker
add a comment |
up vote
0
down vote
favorite
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.
mysql docker
Duplicate of stackoverflow.com/questions/24319662/…. Should be exactly your case.
– wwerner
Nov 22 at 17:58
Possible duplicate of From inside of a Docker container, how do I connect to the localhost of the machine?
– David Maze
Nov 22 at 18:29
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
mysql docker
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.
mysql docker
mysql docker
edited Nov 22 at 17:33
asked Nov 22 at 17:10
Calicoder
182218
182218
Duplicate of stackoverflow.com/questions/24319662/…. Should be exactly your case.
– wwerner
Nov 22 at 17:58
Possible duplicate of From inside of a Docker container, how do I connect to the localhost of the machine?
– David Maze
Nov 22 at 18:29
add a comment |
Duplicate of stackoverflow.com/questions/24319662/…. Should be exactly your case.
– wwerner
Nov 22 at 17:58
Possible duplicate of From inside of a Docker container, how do I connect to the localhost of the machine?
– David Maze
Nov 22 at 18:29
Duplicate of stackoverflow.com/questions/24319662/…. Should be exactly your case.
– wwerner
Nov 22 at 17:58
Duplicate of stackoverflow.com/questions/24319662/…. Should be exactly your case.
– wwerner
Nov 22 at 17:58
Possible duplicate of From inside of a Docker container, how do I connect to the localhost of the machine?
– David Maze
Nov 22 at 18:29
Possible duplicate of From inside of a Docker container, how do I connect to the localhost of the machine?
– David Maze
Nov 22 at 18:29
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435642%2fhow-to-access-a-mysql-database-on-the-same-host-from-within-a-docker-container%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435642%2fhow-to-access-a-mysql-database-on-the-same-host-from-within-a-docker-container%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Duplicate of stackoverflow.com/questions/24319662/…. Should be exactly your case.
– wwerner
Nov 22 at 17:58
Possible duplicate of From inside of a Docker container, how do I connect to the localhost of the machine?
– David Maze
Nov 22 at 18:29