docker-compose 部署golang,mysql, 远程,127.0.0.1均可访问容器mysql, 但go容器里连不上. docker-compose.yaml文件如下:
version: '2'
services:
order_mysql:
networks:
- test_network
image: mysql
command: --default-authentication-plugin=mysql_native_password
container_name: "order_mysql"
ports:
- "3333:3306"
expose:
- "3306"
environment:
MYSQL_DATABASE: order
MYSQL_USER: root
MYSQL_PASSWORD: 123456
TZ: Asia/Shanghai
restart: always
volumes:
- "./mysql/db:/var/lib/mysql"
- "./mysql/conf/my.cnf:/etc/my.cnf"
- "./mysql/init:/docker-entrypoint-initdb.d/"
order_redis:
image: redis
command: --requirepass 12345678
container_name: "order_redis"
ports:
- "6666:6379"
volumes:
- "./redis:/var/lib/redis"
networks:
- test_network
order_golang:
depends_on:
- order_mysql
- order_redis
build: .
ports:
- "2020:2020"
tty: true
networks:
- test_network
links:
- order_mysql:order_mysql
- order_redis:order_redis
networks:
test_network:
host使用的是别名order_mysql的地址, 网段也分配了,order_golang容器编译没问题,容器连mysql怎么连不上
dial tcp 172.21.0.2:3306: connect: connection refused
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…