常用软件Docker安装

MongoDB

在Docker安装MongoDb需要设置本地数据的存储路径和映射端口到本地:
sudo docker run –name mongodb -d -p 27017:27017 -v /data/mongodb:/data/db mongo
如果在本地应用访问,需要使用连接串:mongodb://localhost:27017
在本地安装客户端可以管理数据库,下载地址:https://www.mongodb.com/products/compass

Kafka

Kafka需要zookeeper的支持,所要,在Docker中安装的最好办法是使用docker compose。在github有kafka安装的项目,https://github.com/conduktor/kafka-stack-docker-compose。缺省情况下,kafka的端口在本地ip地址暴露,如果希望对外暴露,需要修改相应的配置。

KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka2:19093,EXTERNAL://50.10.2.3:9093,DOCKER://host.docker.

下面是完整的单节点docker compose配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
version: '2.1'

services:
zoo1:
image: confluentinc/cp-zookeeper:7.3.2
hostname: zoo1
container_name: zoo1
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_SERVERS: zoo1:2888:3888

kafka1:
image: confluentinc/cp-kafka:7.3.2
hostname: kafka1
container_name: kafka1
ports:
- "9092:9092"
- "29092:29092"
- "9999:9999"
environment:
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka1:19092,EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092,DOCKER://host.docker.internal:29092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,DOCKER:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
KAFKA_BROKER_ID: 1
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_JMX_PORT: 9999
KAFKA_JMX_HOSTNAME: ${DOCKER_HOST_IP:-127.0.0.1}
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true"
depends_on:
- zoo1

MySQL

首先获取MySQL的镜像:
docker pull mysql
然后运行:
docker run –name some-mysql -v c:/mysqldata:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mypass -d mysql:latest

这里使用-v将数据库保存文件的路径/var/lib/mysql映射到宿主机,使用-p映射端口,并通过环境变量设置root用户的初始密码。安装完成后,可以使用MySQL Workbench等工具进行管理。

需要注意:有些客户端使用密码连接时会出现错误:
Client does not support authentication protocol requested by server; consider upgrading MySQL client(客户端不支持服务器请求的身份验证协议;请考虑升级MySQL客户端)

这种情况下,如果不升级客户端,可以采用下面的方式解决,执行如下sql语句:
alter user ‘root‘@’%’ identified by ‘YOURPASSWORD’ password expire never
alter user ‘root‘@’%’ identified with mysql_native_password by ‘YOURPASSWORD’
flush privileges

keycloak是开源的认证服务器

docker run -p 8080:8080 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:26.0.2 start-dev