docker-compose 方式安装kafka

一、kafka docker-compose.yml 文件

version: '2'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    image: wurstmeister/kafka:2.11-0.11.0.3
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://selton.cn:9092
      KAFKA_LISTENERS: PLAINTEXT://:9092
      KAFKA_ZOOKEEPER_CONNECT: selton.cn:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

二、docker-compose 快速部署mysql和redis
创建docker-compose.yml文件,并填写如下配置。

version: '3'
services:
  mysql-dev:
    #image:mysql: 5.7
    #container_name: mysql-dev
    image: "docker.io/mysql:latest"
    container_name: mysql
    restart: always
    hostname: localhost
    network_mode: bridge
    ports:
      - "3306:3306"
    volumes: ##数据目录,要确保先创建好
      - ./mysql:/var/lib/mysql
      - ./my.cnf:/etc/mysql/conf.d/my.cnf
    environment: #root账号的密码
      - MYSQL_ROOT_PASSWORD=123zxc
  redis-dev:
    image: redis:3
    container_name: redis-dev
    hostname: localhost
    network_mode: bridge                       ### Redis启动的密码
    command: redis-server /usr/local/etc/redis.conf --requirepass 123zxc
    volumes:
      - ./redis/redis.conf:/usr/local/etc/redis/redis.conf
    ports:
      - "6379:6379"

常用命令总结:

##启动组件
docker-compose up

# 注意文件名一定是 docker-compose.yml才能运行成功,
#若不是这个文件名,则需要指定文件名, filename 对应文件名
docker-compose -f filename up

# 关闭docker-compose 服务
docker-compose down

# 或者
docker-compose -f filename down

其他常用命令可以通过 docker-compose --help查看

参考: https://www.cnblogs.com/raora...

你可能感兴趣的:(docker)