Anyway to make the node-exporter and cadvisor local only to the prometheus container

+1 vote

I am using prometheus, node-exporter, and cadvisor services successfully inside a docker container, all on different ports of the same hosts. I'm using docker compose for all the services:

version: '2'


volumes:
    grafana_data: {}

services:

    prometheus:
        image: prom/prometheus
        privileged: true
        volumes:
            - ./prometheus.yml:/etc/prometheus/prometheus.yml
            - ./alertmanager/alert.rules:/alertmanager/alert.rules
        command:
            - '--config.file=/etc/prometheus/prometheus.yml'
        ports:
            - '9090:9090'

    node-exporter:
        image: prom/node-exporter
        ports:
            - '9100:9100'
    cadvisor:
        image: google/cadvisor:latest 
        privileged: true
        volumes:
            - /:/rootfs:ro
            - /var/run:/var/run:rw
            - /var/lib/docker/:/var/lib/docker:ro
            - /dev/disk/:/dev/disk:ro
            - /cgroup:/sys/fs/cgroup:ro
        ports:
            - '8080:8080'

I need only prometheus to access cadvisor. I want to know if there's any way to make the cadvisor service local only to the container because at the moment it is accessible outside of the contatiner.

Apr 6, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
2,210 views

2 answers to this question.

+1 vote
The simple solution to your problem would be to close the ports for that service. Just delete the ports section for each of those services. Also, you for container to container communication you could use container ports instead of your service ports. You can reference the target container by its service name.
answered Apr 6, 2018 by ajs3033
• 7,300 points
0 votes

If you don't want to access the service externally, don't publish the ports for that service, delete the ports section from each of those services. The resulting compose file will look like:

version: '2'
volumes:
    grafana_data: {}
services:
    prometheus:
        image: prom/prometheus
        privileged: true
        volumes:
            - ./prometheus.yml:/etc/prometheus/prometheus.yml
            - ./alertmanager/alert.rules:/alertmanager/alert.rules
        command:
            - '--config.file=/etc/prometheus/prometheus.yml'
        ports:
            - '9090:9090'

    node-exporter:
        image: prom/node-exporter
        # removed "ports" from here

    cadvisor:
        image: google/cadvisor:latest 
        privileged: true
        volumes:
            - /:/rootfs:ro
            - /var/run:/var/run:rw
            - /var/lib/docker/:/var/lib/docker:ro
            - /dev/disk/:/dev/disk:ro
            - /cgroup:/sys/fs/cgroup:ro
        # removed "ports" from here
answered Oct 18, 2018 by Nilesh
• 7,060 points

Related Questions In DevOps & Agile

–1 vote
1 answer

How to Install and configure puppet agent on the slave node (Job 1)

Hey @Kavitha, where do u want to ...READ MORE

answered Feb 25, 2020 in DevOps & Agile by Sirajul
• 59,230 points
3,392 views
0 votes
1 answer

How to add Node Exporter in Prometheus server?

Hi@akhtar, To add Node Exporter in Prometheus server, you have to ...READ MORE

answered May 28, 2020 in DevOps & Agile by MD
• 95,460 points
2,641 views
+5 votes
1 answer

How to program and get the Digital Ocean ID of the current Droplet from within the Droplet?

You can run curl http://169.254.169.254/metadata/v1/id within the ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by Atul
• 10,240 points
3,474 views
+13 votes
2 answers
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,020 points
2,719 views
+3 votes
1 answer

Unable to find the TargetArguments path While configuring dot cover in VSTS

For your unable to find the TargetArguments ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by ajs3033
• 7,300 points
1,225 views
+1 vote
2 answers

Should I commit Terraform State files to the git repository?

Its better not to commit it to ...READ MORE

answered Aug 3, 2018 in DevOps & Agile by Nilesh
• 7,060 points
3,551 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP