DockerCompose中使用自定义网络的方式实现部署SpringBoot+Mysql+Redis
version: '3.8'
services:
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: 'mydb'
MYSQL_USER: 'user'
MYSQL_PASSWORD: 'password'
MYSQL_ROOT_PASSWORD: 'rootpassword'
networks:
- custom-network
ports:
- "3306:3306"
redis:
image: redis:6.0.9
networks:
- custom-network
ports:
- "6379:6379"
myapp:
build: .
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/mydb
SPRING_DATASOURCE_USERNAME: user
SPRING_DATASOURCE_PASSWORD: password
SPRING_REDIS_HOST: redis
SPRING_REDIS_PORT: 6379
networks:
- custom-network
depends_on:
- mysql
- redis
networks:
custom-network:
driver: bridge
这个Docker Compose文件定义了一个自定义网络custom-network
,它将包含MySQL、Redis和Spring Boot应用的服务。每个服务都连接到这个自定义网络,这样它们可以通过服务名相互通信。Spring Boot应用依赖于MySQL和Redis服务,确保了启动顺序。
评论已关闭