How to run cAdvisor on a different port.
To run with a different port use flag — port to override default port 8080.
i.e : google/cadvisor:latest — port=4000
But this only works if your container not using the host network.
The container does not have its own IP address when using host
mode networking, port-mapping does not take effect and the -p
, --publish
, -P
, and --publish-all
the option is ignored, producing a warning instead.
you can read more here — https://docs.docker.com/network/host/
but why do we need to run containers in the host network mode?
Because, when you run your cAdvisor as a container and if it is not running in the host network it will not able to collect container_task_state metrics!.
So, to run cAdvisor as a container with host network mode and with a different port than 8080 we need to pull the cAdvisor source and build with a different port.
Pull the code from here — https://github.com/google/cadvisor.git
Change the desired port in this file ~\cadvisor-master\cadvisor-master\cmd\cadvisor.go
and here ~\cadvisor-master\cadvisor-master\deploy\Dockerfile
Now build your docker image.
build command: docker build -t google/cadvisor:build.01 -f deploy/Dockerfile .
run your cAdvisor with host network mode, you should be able to see your metrics on port 4000 now.
I have used following script to run the cadvisor
docker run -d — name cadvisor — restart=always — log-opt max-size=50m
— volume=/:/rootfs:ro \
— volume=/sys:/sys:ro \
— volume=/cgroup:/cgroup:ro \
— volume=/var/run:/var/run:rw \
— volume=/var/lib/docker/:/var/lib/docker:ro \
— volume=/dev/disk/:/dev/disk:ro — device=/dev/kmsg \
— volume=/sys/fs/cgroup/cpu,cpuacct:/sys/fs/cgroup/cpuacct,cpu \
— network=host google/cadvisor:build.01 — enable_load_reader=true
Thanks for reading.