刚接触docker,目前我是有一个springboot项目,需要部署到服务器。
我是这样设想的,springboot.jar运行在宿主机。
docker运行nginx和mysql
网络使用宿主机的,就是host,
docker-compose.yml
version: '3'
services:
mysql:
image: mysql:latest
restart: always
network_mode: host
environment:
MYSQL_DATABASE: user
MYSQL_ROOT_PASSWORD: 123456
volumes:
- ./mysql:/var/lib/mysql
ports:
- "3306:3306"
nginx:
image: nginx:latest
restart: always
network_mode: host
ports:
- "80:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- /www/server/nginx/conf/certs/a.key:/etc/nginx/certs/a.key
- /www/server/nginx/conf/certs/a.pem:/etc/nginx/certs/a.pem
- ./nginx:/usr/share/nginx/html
mysql运行在3306,我在宿主机运行我的jar包,没法连接docker的mysql,是怎么回事,jar里面是127.0.0.1:3306