首先,因为docker-compose的version有向下兼容的好处,最好不要写version属性来指明当前的解析版本。
其次,在对一个service进行ip的指定时,需要先定义一个network,具体的参考下面。
services:
webapp:
build: ./
ports:
- 8080:8080
environment:
- TZ=Asia/Shanghai
networks:
mynet:
ipv4_address: 172.18.0.3
mysql:
image: mysql:8.0.13
environment:
- MYSQL_ROOT_PASSWORD=20021218
- TZ=Asia/Shanghai
networks:
mynet:
ipv4_address: 172.18.0.2
networks:
mynet:
driver: bridge
ipam:
config:
- subnet: 172.18.0.0/24
gateway: 172.18.0.1