How to run cAdvisor on a different port. — For Containers

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 —

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 —

Change the desired port in this file ~\cadvisor-master\cadvisor-master\cmd\cadvisor.go

Port number changed to 4000

and here ~\cadvisor-master\cadvisor-master\deploy\Dockerfile

Port number changed to 4000

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.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Basics of Python Programming Part — 1 | Python Tutorial

Engineering Manager Varietals

why do astronomers need programming?

Deploying a high-availability 3 tier web application on OCI using Terraform

3 Layers of Protection

VSCode Extensions You Should Know

Installing Prometheus on Kubernetes with ArgoCD

Mac Os Catalina Can’t Run 32 Bit Apps

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
durairaja sivam

durairaja sivam

More from Medium

How to Install Magento 2 Using Composer in Ubuntu/Localhost

How to Install Magento 2 Using Composer in Ubuntu/Localhost

Automate storageaccount deployment using terraform

Creating a Helm chart to deploy a Flask web-app on the Kubernetes cluster

Kubernetes Inter-pod anti-affinity and de-schedule