From 33f23c291fb351b12715e4baf42ae4a62247eff3 Mon Sep 17 00:00:00 2001 From: j475523225 <475523225@qq.com> Date: Thu, 25 Nov 2021 16:15:23 +0800 Subject: [PATCH] add docker-compose env file, Mac compatible --- .gitignore | 3 +-- config/config.yaml | 12 ++++++------ docker-compose.yaml | 36 ++++++++++++++++++------------------ env-example | 30 ++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 env-example diff --git a/.gitignore b/.gitignore index 532c7da35..336aa27b8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,4 @@ components logs out-test .github - - +.idea diff --git a/config/config.yaml b/config/config.yaml index 51d6451b8..50b4b7b08 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -5,10 +5,10 @@ serverversion: 1.0.3 #---------------Infrastructure configuration---------------------# etcd: etcdSchema: openIM - etcdAddr: [ 127.0.0.1:2379 ] + etcdAddr: [ etcd:2379 ] mysql: - dbMysqlAddress: [ 127.0.0.1:13306 ] + dbMysqlAddress: [ mysql:3306 ] dbMysqlUserName: root dbMysqlPassword: openIM dbMysqlDatabaseName: openIM @@ -19,7 +19,7 @@ mysql: dbMaxLifeTime: 120 mongo: - dbAddress: [ 127.0.0.1:37017 ] + dbAddress: [ mongo:27017 ] dbDirect: false dbTimeout: 10 dbDatabase: openIM @@ -30,7 +30,7 @@ mongo: dbRetainChatRecords: 7 redis: - dbAddress: 127.0.0.1:16379 + dbAddress: redis:6379 dbMaxIdle: 128 dbMaxActive: 0 dbIdleTimeout: 120 @@ -38,10 +38,10 @@ redis: kafka: ws2mschat: - addr: [ 127.0.0.1:9092 ] + addr: [ kafka:9092 ] topic: "ws2ms_chat" ms2pschat: - addr: [ 127.0.0.1:9092 ] + addr: [ kafka:9092 ] topic: "ms2ps_chat" consumergroupid: msgToMongo: mongo diff --git a/docker-compose.yaml b/docker-compose.yaml index 07b52e51b..1818067ef 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,38 +3,37 @@ version: "3" services: mysql: - image: mysql:5.7 + image: mysql:${MYSQL_VERSION} ports: - - 13306:3306 - - 23306:33060 + - ${MYSQL_3306_PORT}:3306 container_name: mysql volumes: - ./components/mysql/data:/var/lib/mysql - /etc/localtime:/etc/localtime environment: - MYSQL_ROOT_PASSWORD: openIM + MYSQL_ROOT_PASSWORD: ${MYSQL_PWD} restart: always mongodb: - image: mongo:4.0 + image: mongo:${MONGO_VERSION} ports: - - 37017:27017 + - ${MONGO_PORT}:27017 container_name: mongo volumes: - ./components/mongodb/data/db:/data/db - ./components/mongodb/data/logs:/data/logs - ./components/mongodb/data/conf:/etc/mongo environment: - - MONGO_INITDB_ROOT_USERNAME=openIM - - MONGO_INITDB_ROOT_PASSWORD=openIM + - MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USERNAME} + - MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PWD} #TZ: Asia/Shanghai restart: always redis: - image: redis + image: redis:${REDIS_VERSION} ports: - - 16379:6379 + - ${REDIS_PORT}:6379 container_name: redis volumes: - ./components/redis/data:/data @@ -51,7 +50,7 @@ services: zookeeper: image: wurstmeister/zookeeper ports: - - 2181:2181 + - ${ZOOKEEPER_PORT}:2181 container_name: zookeeper volumes: - /etc/localtime:/etc/localtime @@ -67,18 +66,17 @@ services: environment: TZ: Asia/Shanghai KAFKA_BROKER_ID: 0 - KAFKA_ZOOKEEPER_CONNECT: 127.0.0.1:2181 - KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092 + KAFKA_ZOOKEEPER_CONNECT: ${KAFKA_ZOOKEEPER_CONNECT} + KAFKA_ADVERTISED_LISTENERS: ${KAFKA_ADVERTISED_LISTENERS} KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092 - network_mode: "host" depends_on: - zookeeper etcd: image: quay.io/coreos/etcd ports: - - 2379:2379 - - 2380:2380 + - ${ETCD_2379_PORT}:2379 + - ${ETCD_2380_PORT}:2380 container_name: etcd volumes: - /etc/timezone:/etc/timezone @@ -89,8 +87,11 @@ services: command: /usr/local/bin/etcd --name etcd0 --data-dir /etcd-data --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-advertise-peer-urls http://0.0.0.0:2380 --initial-cluster etcd0=http://0.0.0.0:2380 --initial-cluster-token tkn --initial-cluster-state new open_im_server: - image: openim/open_im_server + image: openim/open_im_server:${OPEN_IM_SERVER_VERSION} container_name: open_im_server + ports: + - ${OPEN_IM_API_PORT}:10000 + - ${OPEN_IM_SDK_WS_PORT}:30000 volumes: - ./logs:/Open-IM-Server/logs - ./config/config.yaml:/Open-IM-Server/config/config.yaml @@ -104,7 +105,6 @@ services: - mongodb - redis - etcd - network_mode: "host" logging: driver: json-file options: diff --git a/env-example b/env-example new file mode 100644 index 000000000..594f73c60 --- /dev/null +++ b/env-example @@ -0,0 +1,30 @@ +#mysql config +MYSQL_VERSION=5.7 +MYSQL_PWD=openIM +MYSQL_3306_PORT=3306 + +#mongodb config +MONGO_VERSION=4.0 +MONGO_PORT=27017 +MONGO_ROOT_USERNAME=openIM +MONGO_ROOT_PWD=openIM + +#redis config +REDIS_VERSION=latest +REDIS_PORT=6379 + +#zookeeper config +ZOOKEEPER_PORT=2181 + +#kafka config +KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 +KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092 + +#etcd config +ETCD_2379_PORT=2379 +ETCD_2380_PORT=2380 + +#open-im-server config +OPEN_IM_SERVER_VERSION=latest +OPEN_IM_SDK_WS_PORT=30000 +OPEN_IM_API_PORT=10000