docker-compose构建开发常用组件

命令篇

简单的两个命令:启动、暂停
启动条件:命令执行目录下必须有compose文件,文件名必须为docker-compose.yml

#启动当前目录下的文件 (-d参数表示后台启动)
docker-compose up -d

#暂停当前目录下的服务
docker-compose down

常用组件共享篇

分享一个docker-compose.yml文件,其中包含redis、postgresql 、mysql、rabbitmq等,可以根据需求进行删减。

version: '3.1'
services:
  redis:
    image: redis:6.0.8
    restart: always
    container_name: redis
    ports:
      - 6379:6379
    volumes:
      - ./conf/redis.conf:/etc/redis/redis.conf:rw
      - ./data:/data:rw
    command:
      redis-server /etc/redis/redis.conf --appendonly yes
  postgresql:
    restart: always
    image: postgres:13.1
    container_name: postgresql
    ports:
      - 5432:5432
    volumes:
      - ./posgresql:/var/lib/postgresql/data:Z
    environment:
      - POSTGRES_USER=roma
      - POSTGRES_PASSWORD=19941108Aa
      - PGDATA=/var/lib/postgresql/data/pgdata
  minio:
    restart: always
    image: minio/minio
    container_name: minio
    ports:
      - 9000:9000
    environment:
      - MINIO_ACCESS_KEY=admin
      - MINIO_SECRET_KEY=19941108Aa
    command: server /data
    volumes:
      - /mnt/data:/data
  mariadb:
    restart: always
    image: "mariadb:10.5.3"
    container_name: mariadb
    ports:
      - "3306:3306"
    volumes:
      - ./mariadb/data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: "19941108Aa"
  rabbitmq:
    restart: always
    image: rabbitmq:3.8.12-management
    container_name: rabbitmq
    hostname: rabbitmq
    ports:
      - 15672:15672
      - 5672:5672
    volumes:
      - ./rabbitmq:/var/lib/rabbitmq
    environment:
      - RABBITMQ_DEFAULT_USER=admin
      - RABBITMQ_DEFAULT_PASS=12345678Aa

kafka+zk

version: '3.1'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    # always restart
    restart: always
    ports:
      - 2181:2181
  kafka:
    image: wurstmeister/kafka
    container_name: kafka
    ports:
      - 9092:9092
    # host ip
    environment:
      KAFKA_ADVERTISED_HOST_NAME: kafka
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    # always restart
    restart: always
    volumes:
      - ./docker.sock:/var/run/docker.sock

你可能感兴趣的:(docker,docker)