无法从同一机器上运行的其他docker连接器连接到mysql

时间:2020-07-30 18:19:18

标签: mysql docker

这是我的ubuntu 18.04系统的docker-compose.yml文件

version: '3.1'
services:
  zookeeper:
    image: confluentinc/cp-zookeeper
    ports:
      - 2181
    environment:
      - ZOOKEEPER_CLIENT_PORT=2181
      - ZOOKEEPER_TICK_TIME=2000
      - ZOOKEEPER_SYNC_LIMIT=2
  kafka:
    image: confluentinc/cp-kafka
    depends_on:
      - zookeeper
    ports:
      - 9092
      - 9094:9094
    environment:
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
      # setup :9092 for access inside the docker network, 9094 for outside (ie host)
      - KAFKA_LISTENERS=INTERNAL://kafka:9092,OUTSIDE://kafka:9094
      - KAFKA_ADVERTISED_LISTENERS=INTERNAL://kafka:9092,OUTSIDE://localhost:9094
      - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,OUTSIDE:PLAINTEXT
      - KAFKA_INTER_BROKER_LISTENER_NAME=INTERNAL
      - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
      - KAFKA_NUM_PARTITIONS=10

  connect:
    network_mode: host
    image:  logan/kafk-connect:part1
    depends_on:
       - kafka
    ports:
       - "8083:8083"
    environment:
          CONNECT_BOOTSTRAP_SERVERS: localhost:9094
          CONNECT_REST_PORT: 8083
          CONNECT_GROUP_ID: quickstart-avro
          CONNECT_KEY_CONVERTER: io.confluent.connect.avro.AvroConverter
          CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter
          CONNECT_INTERNAL_KEY_CONVERTER: org.apache.kafka.connect.json.JsonConverter
          CONNECT_INTERNAL_VALUE_CONVERTER: org.apache.kafka.connect.json.JsonConverter
          CONNECT_REST_ADVERTISED_HOST_NAME: localhost
          CONNECT_CONFIG_STORAGE_TOPIC: quickstart-avro-config
          CONNECT_OFFSET_STORAGE_TOPIC: quickstart-avro-offsets
          CONNECT_STATUS_STORAGE_TOPIC: quickstart-avro-status
          CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1 
          CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1 
          CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1
          CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL: http://localhost:8081
          CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: http://localhost:8081
          CONNECT_LOG4J_ROOT_LOGLEVEL: DEBUG 
          CONFIG_STORAGE_TOPIC: my_connect_configs
          CONNECT_PLUGIN_PATH: /usr/share/java,/etc/kafka-connect/jars/tmp/quickstart/file:/tmp/quickstart/tmp/quickstart/jars:/etc/kafka-connect/jars
     

  mysql:
    network_mode: host
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
        - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: alphabeta

  landoopui:
    image: landoop/kafka-connect-ui
    links:
    - connect
    ports:
     - "8000:8000"
    environment: 
        CONNECT_URL: http://localhost:8083/

我正在docker机器上运行mysql。我能够从远程应用程序成功连接到mysql,但是我不知道为什么我不能从我的connect容器连接到mysql。尽管我能够从远程应用程序连接到mysql,并且能够从其他远程mysql连接我的连接容器。

我已经尝试过这些网址"jdbc:mysql://localhost:3306/kafkastudent?user=root&password=alphabeta",

"jdbc:mysql://127.0.0.1:3306/kafkastudent?user=root&password=alphabeta",

"jdbc:mysql://serverip:3306/kafkastudent?user=root&password=alphabeta",

但是它总是会导致错误的通信链接失败。

相似的问题-https://serverfault.com/questions/914991/cant-access-mysql-database-in-docker-container-from-another-container?newreg=77b396cf0ad4480d80e2552282d11743

0 个答案:

没有答案