让我们假设这个docker-compose.yml 文件:
version: '2'
services:
zabbix-frontend:
restart: always
image: zabbix/zabbix-web-nginx-mysql
environment:
- DB_SERVER_HOST=someserver
[...]
some-application:
restart: always
image: yourapplication:latest
您的 some-application 容器应连接到 http://zabbix-frontend 以使用 API。
从应用程序容器内测试 http 可达性(示例中为a5d95c2cc9a2):
# docker exec -it a5d95c2cc9a2 sh
sh-4.2# curl -i -X POST -H 'Content-type:application/json' \
-d '{"jsonrpc":"2.0","method":"user.login", \
"params":{ "user":"youruser","password":"somepassword"},"auth":null,"id":0}' \
http://zabbix-frontend/api_jsonrpc.php
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 21 Jan 2019 19:17:55 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/7.1.17
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
{"jsonrpc":"2.0","result":"xxxxxxxxxxxxxxxxx","id":0}