Docker Compose模板(Spring Boot + mysql + redis + rabbitmq):
注:需要将application.yml中的host替换为容器名称
点击查看代码
services:backend:container_name: textgenbuild:context: .dockerfile: Dockerfilerestart: on-failurevolumes:- type: bindsource: /srv/textgen/log/target: /var/run/textgen-log/- type: bindsource: /srv/textgen/storage/target: /var/run/textgen-storage/ports:- "8080:8080"depends_on:- mysql- redis- rabbitmqmysql:image: mysql:8.0.36-debiancontainer_name: textgen-mysqlrestart: on-failurevolumes:- type: bindsource: /srv/textgen/mysqltarget: /var/lib/mysql- type: bindsource: ./sql/tables.sqltarget: /tmp/tables.sqlports:- 3306environment:MYSQL_USER: textgen-userMYSQL_PASSWORD: some-passwordMYSQL_DATABASE: textgenTZ: Asia/ShanghaiMYSQL_ROOT_PASSWORD: gE61dRVXcommand:--init-file /tmp/tables.sqlredis:image: redis:7.2.4-bookwormcontainer_name: textgen-redisrestart: on-failureports:- 6379:6379rabbitmq:image: rabbitmq:3.9.11-managementcontainer_name: textgen-rabbitmqrestart: on-failurevolumes:- type: bindsource: /srv/textgen/rabbitmqtarget: /var/lib/rabbitmq- "/srv/textgen/resource/rabbitmq_delayed_message_exchange-3.9.0.ez:/plugins/rabbitmq_delayed_message_exchange-3.9.0.ez"ports:- 5672- 15672:15672environment:RABBITMQ_DEFAULT_USER: textgen-userRABBITMQ_DEFAULT_PASS: some-passwordcommand: >sh -c "rabbitmq-plugins enable --offline rabbitmq_delayed_message_exchange &&rabbitmq-server"
点击查看代码
USE mysql;
UPDATE user SET host = '%' WHERE user = 'root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'gE61dRVX';
FLUSH PRIVILEGES;