运维开发网

使用docker compose 安装zookeeper、kafka,启动自己的jar 包

运维开发网 https://www.qedev.com 2021-01-16 12:27 出处:51CTO 作者:wx60004948e2e17
dockercompose 启动依赖kafka的jar 项目

编辑 docker-compose.yml 宿主机的ip是10.10.10.8

zookeeper:

image: zookeeper:3.4.14

container_name: zookeeper

environment:

  • ALLOW_ANONYMOUS_LOGIN=yes

    expose:

  • "2181"

    volumes:

  • "/path/to/zookeeper-persistence:/opt/zookeeper"

    networks:

  • "net1"

    ports:

  • "2181:2181"

    restart: always

kafka:

image: wurstmeister/kafka

container_name: kafka

expose:

  • "9092"

    ports:

  • "9092:9092"

    networks:

  • "net1"

    depends_on:

  • "zookeeper"

    environment:

    KAFKA_ADVERTISED_HOST_NAME: 10.10.10.8 ##宿主机ip

    KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.10.10.8:9092

    KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092

    KAFKA_ADVERTISED_PORT: 9092

    KAFKA_MESSAGE_MAX_BYTES: 20000000

    KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

    KAFKA_auto_create_topics_enable: "true"

    KAFKA_HEAP_OPTS: "-Xmx1024M -Xms128M"

    volumes:

  • /root/war/root/kafkadata/data:/kafka
  • /root/war/root/kafkadata/docker.sock:/var/run/docker.sock

    restart: always

myjar:

image: java:8u111

container_name: myjar

volumes:

  • "/opt/service:/mnt"
  • "/opt/service/logs:/logs"

    depends_on:

  • "kafka"

    expose:

  • "990"
  • "980"

    networks:

  • "net1"

    ports:

  • "990:990"
  • "980:980"

    restart: always

    extra_hosts:

  • "serviceip:10.10.10.8"

    command: [

    'java',

    '-Xmx2048m',

    '-jar',

    '/mnt/myjar.jar'

    ]

    zk、kafka 和myjar 都在一个桥接网络中可以直接通过容器的名字进行互联。

    创建配置中的所有容器

    docker-compose -f docker-compose.yml up

         停止配置中的所有容器
    docker-compose -f docker-compose.yml  stop 

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号