-1

I'am new to docker containerization, So i created one custom image for my application, And now i would like to Access MySQL data from host into docker, I did all application configurations but i am getting Communication exception, means docker is not able to communication with MySQL.

Used the following Dockerfile

FROM ubuntu 
RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "vim","curl","jq","apt-utils"]
ENV PATH $PATH:/opt/java/bin 
ENV PATH $PATH:/opt/confluent/bin
ADD confluent-5.2.1 /opt/confluent 
RUN mkdir java 
ADD jdk1.8.0_221 /opt/java
CMD ["/bin/bash","-c","confluent start schema-registry && ./opt/confluent/bin/connect-standalone ./opt/confluent/etc/schema-registry/connect-avro-standalone.properties ./opt/confluent/etc/kafka-connect-jdbc/source-quickstart-sqlite.properties","-n"] 
Adiii
  • 54,482
  • 7
  • 145
  • 148
  • 1
    A little context here will be nice, which port have you set, show us your docker-compose or your docker file at least. – Greco Jonathan Nov 21 '19 at 11:04
  • FROM ubuntu RUN ["apt-get", "update"] RUN ["apt-get", "install", "-y", "vim","curl","jq","apt-utils"] ENV PATH $PATH:/opt/java/bin ENV PATH $PATH:/opt/confluent/bin ADD confluent-5.2.1 /opt/confluent RUN mkdir java ADD jdk1.8.0_221 /opt/java CMD ["/bin/bash","-c","confluent start schema-registry && ./opt/confluent/bin/connect-standalone ./opt/confluent/etc/schema-registry/connect-avro-standalone.properties ./opt/confluent/etc/kafka-connect-jdbc/source-quickstart-sqlite.properties","-n"] I created this docker file for my application which contains all the source configurations. – Kishor Patil Nov 21 '19 at 11:09
  • how you create connection in your application? – Adiii Nov 21 '19 at 11:52
  • "./opt/confluent/etc/kafka-connect-jdbc/source-quickstart-sqlite.properties" maybe some "quickstart-mysql.properties" would be more appropriate. Also show the configuration you made and the log output. – Olaf Dietsche Nov 21 '19 at 11:59
  • 1
    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) – scones Nov 21 '19 at 12:07
  • Where is the database running? How are you trying to connect to it? – David Maze Nov 21 '19 at 12:36
  • Thank You Everyone! i used below command to run docker container and finally it is working for me (docker run --network="host" -t img-name) – Kishor Patil Nov 22 '19 at 05:19

1 Answers1

-1

i understand your question like this: your application runs inside a docker container. your mysql server runs on the host system. you want your application to connect to that mysql server and don't know how.

when you are using mac or win as a host system, you can use docker.host.internal as mysql-server-address.

when you are not using that, you need to find the ip manually. i usually determine the current container address and change the last number to .1, as this always works for me.

within the following issue, there are more ways to do it: https://github.com/docker/for-linux/issues/264

hope this helps

scones
  • 3,317
  • 23
  • 34