简体   繁体   English

如何将 MySQL 从主机连接到 Docker?

[英]How to connect MySQL from host to Docker?

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. 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与 MySQL 通信。

Used the following Dockerfile使用以下 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"] 

i understand your question like this: your application runs inside a docker container.我这样理解您的问题:您的应用程序在 docker 容器内运行。 your mysql server runs on the host system.您的 mysql 服务器在主机系统上运行。 you want your application to connect to that mysql server and don't know how.您希望您的应用程序连接到该 mysql 服务器并且不知道如何。

when you are using mac or win as a host system, you can use docker.host.internal as mysql-server-address.当您使用 mac 或 win 作为主机系统时,您可以使用docker.host.internal作为 mysql-server-address。

when you are not using that, you need to find the ip manually.当你不使用它时,你需要手动找到 ip。 i usually determine the current container address and change the last number to.1, as this always works for me.我通常确定当前容器地址并将最后一个数字更改为 1,因为这对我总是有效。

within the following issue, there are more ways to do it: https://github.com/docker/for-linux/issues/264在以下问题中,有更多方法可以做到: https://github.com/docker/for-linux/issues/264

hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM