2

I'm trying to startup zabbix in docker, I've created the docker-compose with several services, one is the database. I need start the database first , and after get the ip address from database to setup the other services, but do not know how to do, is already trying to use the links, but without success.

This is my docker-compose.yml

version: "2"
services:
mysql-zabbix :
  image: "mysql:5.7"
  ports:
    - "53306:3306"
  networks:
    - net_zabbix
  volumes:
    - "vol_db_zabbix:/var/lib/mysql"
  environment:
    - "MYSQL_ROOT_PASSWORD=abcd"
    - "MYSQL_DATABASE=zabbix"
    - "MYSQL_USER=zabbix"
    - "MYSQL_PASSWORD=123456"

zabbix-server:
  image: "zabbix/zabbix-server-mysql:alpine-3.4.11"
  ports:
    - "10051:10051"
  networks:
    - net_zabbix
  environment:
    - "DB_SERVER_PORT=53306"
    - DB_SERVER_HOST=zabbix.db
    - "MYSQL_USER=zabbix"
    - "MYSQL_PASSWORD=123456"
  depends_on:
    - mysql-zabbix
  external_links:
    - mysql-zabbix:zabbix.db

zabbix-web:
  image: "zabbix/zabbix-web-apache-mysql:alpine-3.4.11"
  ports:
    - "80:80"
  networks:
    - net_zabbix
  environment:
    - DB_SERVER_HOST=zabbix.db
    - "DB_SERVER_PORT=53306"
    - "MYSQL_USER=zabbix"
    - "MYSQL_PASSWORD=123456"
    - ZBX_SERVER_HOST=zabbix.server
    - "PHP_TZ=America/Sao_Paulo"
  depends_on:
    - zabbix-server
  external_links:
    - mysql-zabbix:zabbix.db
    - zabbix-server:zabbix.server

zabbix-agent:
  image: "zabbix/zabbix-agent:alpine-3.4.11"
  ports:
    - "10050:10050"
  networks:
    - net_zabbix
  environment:
    - "ZBX_HOSTNAME=demo_zabbix"
    - ZBX_SERVER_HOST=zabbix.server
  external_links:
    - zabbix-server:zabbix.server

zabbix-proxy:
  image: "zabbix/zabbix-proxy-sqlite3:alpine-3.4.11"
  ports:
    - "10053:10050"
  networks:
    - net_zabbix
  environment:
    - "ZBX_HOSTNAME=demo_zabbix"
    - ZBX_SERVER_HOST=zabbix.server
  external_links:
    - zabbix-server:zabbix.server

networks:
net_zabbix:

volumes:
vol_db_zabbix:
Sileno Brito
  • 449
  • 1
  • 13
  • 31
  • I don't know zabix and your docker-compose seems to have a lot of unecessary configuration but it seems for me that you should set your `DB_SERVER_HOST=mysql-zabbix` because it's address available inside docker for db. – ttomalak Jul 16 '18 at 22:45

1 Answers1

0

Docker Compose will implicitly create a private network for you, and once it's created that private network, Docker provides a DNS service that will resolve container names to IP addresses. (The explicit networks: declaration isn't harmful and has the same effect.) You can refer to a container by its name and by additional aliases. Docker Compose will register aliases to reach each container under its key in the docker-compose.yml file.

All of this means that you can use the other container names as the values of the various *_HOST environment variables. Note that the ports used are the container internal ports; if you're connecting to a service port that's also being published to the host, it's the port on the right side of the colon.

In your example, you should specify (for different containers as appropriate):

environment:
  - DB_SERVER_HOST=mysql-zabbix
  - DB_SERVER_PORT=3306
  - ZBX_SERVER_HOST=zabbix-server

You do not need to specify links of any sort. depends_on is strictly optional, but if you run docker-compose up zabbix-web, it will also start the things it depends on.

David Maze
  • 130,717
  • 29
  • 175
  • 215