我正在尝试对我需要使用的所有弹性服务进行 dockerize。docker-compose 文件如下所示
version: '3'
services:
redis:
build: ./docker/redis
postgresql:
build: ./docker/postgresql
ports:
- "5433:5432"
env_file:
- .env
graphql:
build: .
command: npm run start
volumes:
- ./logs/:/usr/app/logs/
ports:
- "3000:3000"
env_file:
- .env
depends_on:
- "redis"
- "postgresql"
links:
- "redis"
- "postgresql"
elasticsearch:
build: ./docker/elasticsearch
container_name: elasticsearch
networks:
- elastic
ports:
- "9200:9200"
depends_on:
- "graphql"
links:
- "kibana"
kibana:
build: ./docker/kibana
container_name: kibana
ports:
- "5601:5601"
depends_on:
- "graphql"
networks:
- elastic
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
metricbeat:
build: ./docker/metricbeat
depends_on:
- "graphql"
- "elasticsearch"
- "kibana"
volumes:
- /proc:/hostfs/proc:ro
- /sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro
- /:/hostfs:ro
networks:
- elastic
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
command:
- "-system.hostfs=/hostfs"
packetbeat:
build: ./docker/packetbeat
depends_on:
- "graphql"
- "elasticsearch"
- "kibana"
cap_add:
- NET_ADMIN
networks:
- elastic
environment:
- ELASTICSEARCH_URL=http://127.0.0.1:9200
logstash:
build: ./docker/logstash
ports:
- "9600:9600"
volumes:
- ./logs:/usr/logs
depends_on:
- "graphql"
- "elasticsearch"
- "kibana"
networks:
- elastic
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
networks:
elastic:
driver: bridge
现在一切运行良好,但问题是 packetbeat 仅在其自己的 docker 容器内捕获网络。在弹性文档参考 - https://www.elastic.co/guide/en/beats/packetbeat/master/running-on-docker.html
它说我需要启用“主机”网络才能捕获所有始发网络和到达物理主机的网络。但是,由于我已将网络配置为,因此-elastic
无法将其他主机网络接口添加到 packetbeat。如果我删除-elastic
网络并添加-host
网络,我将无法连接到 elasticsearch,因为 DNS elasticsearch 不再存在于不同的网络中。我该如何克服这个问题?