我需要将应用程序容器和 mysql 服务器上传到同一台主机,但是容器找不到 mysql 服务器,你能帮我吗?
DOCKER 撰写version: '3'
services:
proxy:
image: nginx
ports:
- "80:80"
- "443:443"
volumes:
- /home/docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
- /home/docker/nginx/ssl/:/etc/nginx/ssl/
links:
- zabbix-web:zabbix-web
zabbix-web:
image: zabbix/zabbix-web-nginx-mysql:ubuntu-latest
links:
- zabbix-server:zabbix-server
- mysql-server:mysql-server
environment:
- MYSQL_USER=user
- MYSQL_PASSWORD=pass
- ZBX_SERVER_HOST=zabbix-server
- TZ=America/Sao_Paulo
zabbix-server:
image: zabbix/zabbix-server-mysql:ubuntu-latest
links:
- mysql-server:mysql-server
ports:
- "10051:10051"
volumes:
- /home/docker/zabbix-server/script/:/usr/lib/zabbix/alertscripts
environment:
- MYSQL_USER=user
- MYSQL_PASSWORD=pass
mysql-server:
image: mysql/mysql-server:5.6
volumes:
- /home/data/mysql/:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=pass
错误
#docker logs docker_zabbix-server_1
**Deploying Zabbix server with mysql database
** Preparing the system
** Preparing Zabbix server
********************
* DB_SERVER_HOST: mysql-server
* DB_SERVER_PORT: 3306
* DB_SERVER_DBNAME: zabbix
* DB_SERVER_ZBX_USER: user
* DB_SERVER_ZBX_PASS: pass
********************
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...
**** MySQL server is not available. Waiting 5 seconds...
答案1
看起来您缺少几个环境变量。
首先,在您的mysql-server
服务中,您仅指定MYSQL_ROOT_PASSWORD
。这不会创建您在zabbix-web
和zabbix-server
服务中使用的用户和密码组合。您还需要指定MYSQL_DATABASE=zabbix
、MYSQL_USER=user
和MYSQL_PASSWORD=pass
。
然后,根据 Zabbix 镜像文档,您需要指定DB_SERVER_HOST=mysql-server
以便 Zabbix 知道如何访问链接的 MySQL 服务器。也有,MYSQL_DATABASE
但它默认为zabbix
我们在 MySQL 服务中指定要创建的内容,因此默认应该有效。