From f49d061f45911e955bfaa53e8f21b9dc68de360a Mon Sep 17 00:00:00 2001 From: Dylan Da Costa Date: Sun, 14 Dec 2025 16:01:25 -0500 Subject: [PATCH 1/7] Add entrypoint wrapper to preserve -logtostderr flag Introduce entrypoint.sh to maintain the existing -logtostderr behavior while allowing for future healthcheck enhancements. --- deploy/entrypoint.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 deploy/entrypoint.sh diff --git a/deploy/entrypoint.sh b/deploy/entrypoint.sh new file mode 100644 index 0000000000..8cbf3e28e8 --- /dev/null +++ b/deploy/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh +set -e + +# Execute cadvisor with all provided arguments +exec /usr/bin/cadvisor -logtostderr "$@" \ No newline at end of file From bc232adf26e2b3a18170d835879efe9c346f56d6 Mon Sep 17 00:00:00 2001 From: Dylan Da Costa Date: Sun, 14 Dec 2025 16:02:16 -0500 Subject: [PATCH 2/7] Fix healthcheck to respect custom port flag The Dockerfile healthcheck was using a static port (8080) which caused healthcheck failures when cAdvisor was started with a custom port using the -port flag. This change introduces a healthcheck script that: - Reads the cadvisor process command line from /proc - Dynamically extracts the port from the -port flag - Allows the healthcheck to use the correct port automatically - Preserves the existing -logtostderr behavior Fixes #3618 --- deploy/Dockerfile | 17 +++++++++++------ deploy/healthcheck.sh | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 deploy/healthcheck.sh diff --git a/deploy/Dockerfile b/deploy/Dockerfile index d67c9f7de0..f37d078133 100644 --- a/deploy/Dockerfile +++ b/deploy/Dockerfile @@ -58,14 +58,19 @@ RUN apk --no-cache add libc6-compat device-mapper findutils ndctl thin-provision # Grab cadvisor,libpfm4 and libipmctl from "build" container if they exist (libipmctl only works on amd64/x86_64). COPY --from=build /usr/local/lib/libpfm.so* /usr/local/lib/ -COPY --from=build /usr/local/lib/libipmctl.so* /usr/local/lib/ +# Disable libipmctl due to https://github.com/google/cadvisor/issues/3482 +#COPY --from=build /usr/local/lib/libipmctl.so* /usr/local/lib/ COPY --from=build /go/src/github.com/google/cadvisor/_output/cadvisor /usr/bin/cadvisor -EXPOSE 8080 +COPY deploy/entrypoint.sh /usr/bin/entrypoint.sh +RUN chmod +x /usr/bin/entrypoint.sh + +COPY deploy/healthcheck.sh /usr/bin/healthcheck.sh +RUN chmod +x /usr/bin/healthcheck.sh -ENV CADVISOR_HEALTHCHECK_URL=http://localhost:8080/healthz +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \ + CMD /usr/bin/healthcheck.sh -HEALTHCHECK --interval=30s --timeout=3s \ - CMD wget --quiet --tries=1 --spider $CADVISOR_HEALTHCHECK_URL || exit 1 +# Use entrypoint wrapper +ENTRYPOINT ["/usr/bin/entrypoint.sh"] -ENTRYPOINT ["/usr/bin/cadvisor", "-logtostderr"] diff --git a/deploy/healthcheck.sh b/deploy/healthcheck.sh new file mode 100644 index 0000000000..940b711e8b --- /dev/null +++ b/deploy/healthcheck.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# Default port +PORT=8080 + +# Extract port from the cadvisor process command line +if [ -f /proc/1/cmdline ]; then + CMDLINE=$(tr '\0' ' ' < /proc/1/cmdline) + + # Look for -port=XXXX or --port=XXXX + for arg in $CMDLINE; do + case "$arg" in + -port=*) + PORT="${arg#-port=}" + ;; + --port=*) + PORT="${arg#--port=}" + ;; + esac + done +fi + +wget --quiet --tries=1 --spider "http://localhost:${PORT}/healthz" || exit 1 \ No newline at end of file From 74e259c9c3453ba244c818318e66cbe1ff8c07bd Mon Sep 17 00:00:00 2001 From: Dylan Da Costa Date: Sun, 14 Dec 2025 16:07:52 -0500 Subject: [PATCH 3/7] Add EXPOSE 8080 to document default port Documents the default port and enables automatic port mapping. Users can override with -port flag and custom -p mapping. --- deploy/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/deploy/Dockerfile b/deploy/Dockerfile index f37d078133..03d653c0db 100644 --- a/deploy/Dockerfile +++ b/deploy/Dockerfile @@ -68,6 +68,10 @@ RUN chmod +x /usr/bin/entrypoint.sh COPY deploy/healthcheck.sh /usr/bin/healthcheck.sh RUN chmod +x /usr/bin/healthcheck.sh +# Default port is 8080, but can be changed with -port flag +# Users should expose their custom port with: docker run -p : +EXPOSE 8080 + HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \ CMD /usr/bin/healthcheck.sh From 492e932cbab41ca6c2a3026d6a69040941db0c29 Mon Sep 17 00:00:00 2001 From: Dylan Da Costa <49167952+dylandacosta8@users.noreply.github.com> Date: Tue, 16 Dec 2025 10:44:55 -0500 Subject: [PATCH 4/7] Added cadvisor boilerplate header to deploy/healthcheck.sh --- deploy/healthcheck.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/deploy/healthcheck.sh b/deploy/healthcheck.sh index 940b711e8b..636688c55b 100644 --- a/deploy/healthcheck.sh +++ b/deploy/healthcheck.sh @@ -1,4 +1,18 @@ -#!/bin/sh +#!/bin/bash + +# Copyright 2015 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # Default port PORT=8080 @@ -20,4 +34,4 @@ if [ -f /proc/1/cmdline ]; then done fi -wget --quiet --tries=1 --spider "http://localhost:${PORT}/healthz" || exit 1 \ No newline at end of file +wget --quiet --tries=1 --spider "http://localhost:${PORT}/healthz" || exit 1 From 60c4bfb8ec66c509ba627ef3d9064d8bd4b8d645 Mon Sep 17 00:00:00 2001 From: Dylan Da Costa <49167952+dylandacosta8@users.noreply.github.com> Date: Tue, 16 Dec 2025 10:45:46 -0500 Subject: [PATCH 5/7] Added cadvisor boilerplate header to deploy/entrypoint.sh --- deploy/entrypoint.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/deploy/entrypoint.sh b/deploy/entrypoint.sh index 8cbf3e28e8..985de418dc 100644 --- a/deploy/entrypoint.sh +++ b/deploy/entrypoint.sh @@ -1,5 +1,20 @@ -#!/bin/sh +#!/bin/bash + +# Copyright 2015 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + set -e # Execute cadvisor with all provided arguments -exec /usr/bin/cadvisor -logtostderr "$@" \ No newline at end of file +exec /usr/bin/cadvisor -logtostderr "$@" From a787e8b3bd8e38df5a464e2fe090bfa5c70dfb6a Mon Sep 17 00:00:00 2001 From: Dylan Da Costa <49167952+dylandacosta8@users.noreply.github.com> Date: Tue, 16 Dec 2025 12:25:46 -0500 Subject: [PATCH 6/7] Update copyright year in entrypoint.sh --- deploy/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/entrypoint.sh b/deploy/entrypoint.sh index 985de418dc..4c489dfbfa 100644 --- a/deploy/entrypoint.sh +++ b/deploy/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright 2015 Google Inc. All rights reserved. +# Copyright 2025 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 2ed4e02979b96bd0a333ad2d2a488bab0b745cd7 Mon Sep 17 00:00:00 2001 From: Dylan Da Costa <49167952+dylandacosta8@users.noreply.github.com> Date: Tue, 16 Dec 2025 12:26:34 -0500 Subject: [PATCH 7/7] Update copyright year in healthcheck.sh --- deploy/healthcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/healthcheck.sh b/deploy/healthcheck.sh index 636688c55b..4742dd06f0 100644 --- a/deploy/healthcheck.sh +++ b/deploy/healthcheck.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright 2015 Google Inc. All rights reserved. +# Copyright 2025 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.