使用dockerfile安装各种服务组件
elasticsearch、minio、mongodb、nacos、redis
1、Dockerfile文件
FROM elasticsearch:7.8.0
#添加分词器
ADD elasticsearch-analysis-ik /usr/share/elasticsearch/plugins/elasticsearch-analysis-ik
ENV discovery.type=single-node
2、构建镜像
docker build -f Dockerfile -t elasticsearch .
3、运行容器
需要绑定9200、9300端口
其中,-p 指令指定了容器的端口映射,-d 指令指定了容器在后台运行。
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -d elasticsearch
4、使用到的Dockerfile文件和ik文件内容
相关文件
https://download.csdn.net/download/m0_37924754/88189473
1、Dockerfile文件
# 基础镜像
FROM minio/minio
# author
MAINTAINER It-小白
EXPOSE 9000 9001
ENTRYPOINT ["minio", "server", "/data"]
2、构建镜像
docker build -f Dockerfile -t minio .
3、运行容器
需要绑定9000、9001端口
其中,-p 指令指定了容器的端口映射,-d 指令指定了容器在后台运行,
-v /home/minio/data:/data 挂载数据
-v /home/minio/.minio:/root/.minio 挂载配置
–console-address “:9001” 配置控制台地址
docker run -p 9000:9000 -p 9001:9001 -v /home/minio/data:/data -v /home/minio/.minio:/root/.minio --name minio -d minio --console-address ":9001"
4、相关文件
1、Dockerfile文件
FROM centos:7.5.1804
MAINTAINER It-小白
LABEL Discription="基于centos的mongodb镜像" version="1.0"
RUN mkdir -p /data/usr
ADD mongodb-linux-x86_64-rhel70-5.0.6 /data/usr/mongodb
RUN mkdir /data/usr/mongodb/{data,logs}
ENV PATH /data/usr/mongodb/bin:$PATH
EXPOSE 27017
WORKDIR /data/usr/mongodb/bin/
COPY mongodb.conf .
CMD ["mongod","-f", "mongodb.conf"]
2、构建镜像
docker build -f Dockerfile -t mongodb .
3、运行容器
需要绑定27017 端口
其中,-p 指令指定了容器的端口映射,-d 指令指定了容器在后台运行
docker run -p 27017:27017 --name mongodb -d mongodb
4、相关文件
1、Dockerfile文件
MYSQL_SERVICE_HOST 数据库连接IP
MYSQL_SERVICE_PORT 端口
MYSQL_SERVICE_DB_NAME 数据库名称
MYSQL_SERVICE_USER 数据库账号
MYSQL_SERVICE_PASSWORD 数据库密码
MYSQL_SERVICE_DB_PARAM 数据库连接配置
# 基础镜像
FROM nacos/nacos-server:v2.1.2
# author
MAINTAINER It-小白
EXPOSE 8848 9848 9849
ENV MODE=standalone SPRING_DATASOURCE_PLATFORM=mysql MYSQL_SERVICE_HOST=127.0.0.1 MYSQL_SERVICE_PORT=12306 MYSQL_SERVICE_DB_NAME=yshop_cloud_nacos MYSQL_SERVICE_USER=root MYSQL_SERVICE_PASSWORD=Xyj@0127... MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
ENV JVM_XMS=256m JVM_XMX=256m JVM_XMN=128m JVM_MS=64m JVM_MMS=128m
2、构建镜像
docker build -f Dockerfile -t nacos .
3、运行容器
需要绑定8848 、9848、9849 端口
其中,-p 指令指定了容器的端口映射,-d 指令指定了容器在后台运行
docker run -p 8848:8848 -p 9848:9848 -p 9849:9849 -v /mydata/logs/nacos:/home/nacos/logs --name nacos -d nacos
4、相关文件
1、Dockerfile文件
# 基础镜像
FROM rabbitmq:3.7.7-management
# author
MAINTAINER It-小白
ENV RABBITMQ_DEFAULT_USER=admin RABBITMQ_DEFAULT_PASS=admin
2、构建镜像
docker build -f Dockerfile -t rabbitmq .
3、运行容器
需要绑定15672 、5672端口
其中,-p 指令指定了容器的端口映射,-d 指令指定了容器在后台运行
docker run -p 15672:15672 -p 5672:5672 --name rabbitmq -d rabbitmq
4、相关文件
1、Dockerfile文件
# 基础镜像
FROM redis
# author
MAINTAINER It-小白
2、构建镜像
docker build -f Dockerfile -t redis .
3、运行容器
需要绑定6379 端口
其中,-p 指令指定了容器的端口映射,-d 指令指定了容器在后台运行
–requirepass 密码
docker run -p 6379:6379 -v /mydata/redis/data:/data --name redis redis --requirepass 123456 --appendonly yes
4、相关文件
1、Dockerfile文件
FROM seataio/seata-server:1.6.1
COPY ./resource /seata-server/resources
ENV SEATA_IP=127.0.0.1
ENV SEATA_PORT=8091
2、application.yml文件
COPY ./resource /seata-server/resources 里面的配置文件
修改nacos连接配置
server:
port: 7091
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: ${user.home}/logs/seata
extend:
logstash-appender:
destination: 127.0.0.1:4560
kafka-appender:
bootstrap-servers: 127.0.0.1:9092
topic: logback_to_logstash
console:
user:
username: seata
password: seata
seata:
config:
# support: nacos, consul, apollo, zk, etcd3
type: nacos
nacos:
server-addr: 127.0.0.1:8848
namespace: prod
group: SEATA_GROUP
username: nacos
password: nacos
# 该data-id需要在nacos中在进行配置
data-id: seata.properties
registry:
# support: nacos, eureka, redis, zk, consul, etcd3, sofa
type: nacos
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
namespace: prod
cluster: default
username: nacos
password: nacos
store:
# support: file 、 db 、 redis
mode: db
# server:
# service-port: 8091 #If not configured, the default is '${server.port} + 1000'
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
3、seata.properties
配置放到nacos,修改配置文件中的数据库连接地址、账号、密码
#For details about configuration items, see https://seata.io/zh-cn/docs/user/configurations.html
#Transport configuration, for client and server
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableTmClientBatchSendRequest=false
transport.enableRmClientBatchSendRequest=true
transport.enableTcServerBatchSendResponse=false
transport.rpcRmRequestTimeout=30000
transport.rpcTmRequestTimeout=30000
transport.rpcTcRequestTimeout=30000
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
transport.serialization=seata
transport.compressor=none
#Transaction routing rules configuration, only for the client
service.vgroupMapping.default_tx_group=default
service.vgroupMapping.mall-mall-biz-group=default
service.vgroupMapping.mall-auth-group=default
service.vgroupMapping.mall-upms-biz-group=default
service.vgroupMapping.mall-weixin-biz-group=default
#If you use a registry, you can ignore it
service.default.grouplist=192.168.2.213:8092
service.enableDegrade=false
service.disableGlobalTransaction=false
#Transaction rule configuration, only for the client
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=true
client.rm.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.rm.sagaJsonParser=fastjson
client.rm.tccActionInterceptorOrder=-2147482648
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
client.tm.interceptorOrder=-2147482648
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
#For TCC transaction mode
tcc.fence.logTableName=tcc_fence_log
tcc.fence.cleanPeriod=1h
#Log rule configuration, for client and server
log.exceptionRate=100
#Transaction storage configuration, only for the server. The file, DB, and redis configuration values are optional.
store.mode=db
#These configurations are required if the `store mode` is `db`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `db`, you can remove the configuration block.
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:12306/yshop_cloud_seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=root
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
#Transaction rule configuration, only for the server
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
server.distributedLockExpireTime=10000
server.xaerNotaRetryTimeout=60000
server.session.branchAsyncQueueSize=5000
server.session.enableBranchAsyncRemove=false
server.enableParallelRequestHandle=false
#Metrics configuration, only for the server
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
2、构建镜像
```bash
docker build -f Dockerfile -t redis .
3、运行容器
需要绑定6379 端口
其中,-p 指令指定了容器的端口映射,-d 指令指定了容器在后台运行
–requirepass 密码
docker run -p 6379:6379 -v /mydata/redis/data:/data --name redis redis --requirepass 123456 --appendonly yes
4、相关文件
1、Dockerfile文件
# 基础镜像
FROM openjdk:8u212-jre
MAINTAINER It-小白
ENV TZ=Asia/Shanghai
ENV JAVA_OPTS="-Xms128M -Xmx512M -XX:PermSize=32M -XX:MaxPermSize=64M -Djava.security.egd=file:/dev/./urandom"
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /app
ENV NACOS_ADDRESS=10.0.4.17:8848 SERVER_IP=10.0.4.17
WORKDIR /app
EXPOSE 9202
ADD ./target/app.jar ./
CMD java $JAVA_OPTS -jar app.jar --spring.profiles.active=prod --nacos.server-addr=$NACOS_ADDRESS --nacos.server-ap=$SERVER_IP
2、构建镜像
docker build -f Dockerfile -t java_app .
3、运行容器
需要绑定9000、9001端口
其中,-p 指令指定了容器的端口映射,-d 指令指定了容器在后台运行,
-v /home/minio/data:/data 挂载数据
-v /home/minio/.minio:/root/.minio 挂载配置
–console-address “:9001” 配置控制台地址
docker run -p 9202:9202 -v /mydata/logs/app:/app/logs -v /mydata/data/files/file:/home/files/file -v /mydata/data/files/avatar:/home/files/avatar --name java_app -d java_app
4、相关文件