Support installing extra packages in Docker images at runtime. (#14456)
* Support installing extra packages in Docker images at runtime. This enables users to pull in additional packages more easily if they need to. It also allows us to drop optional runtime dependencies from our base images without making life significantly more difficult for users who actually need them. * Reorganize code and fix issues brought up in review. * Make new variable empty by default instead.
Austin S. Hemmelgarn committed
Feb 21, 2023 at 07:12 UTC
61fea7837f322b5d23ef5b1583973288e3ffa37c
3 files changed
+29
packaging/docker/Dockerfile
+2
@@ -117,6 +117,8 @@ RUN chown -R root:root \
117
ENV NETDATA_LISTENER_PORT 19999
118
EXPOSE $NETDATA_LISTENER_PORT
119
120
+ENV NETDATA_EXTRA_APK_PACKAGES=""
121
+
122
ENTRYPOINT ["/usr/sbin/run.sh"]
123
124
HEALTHCHECK --interval=60s --timeout=10s --retries=3 CMD /usr/sbin/health.sh
packaging/docker/README.md
+14
@@ -157,6 +157,20 @@ Additionally, for each stable release, three tags are pushed, one with the full
157
that would match that tag (for example, if `v1.30.1` were to be published, the `v1.30` tag would be updated to
158
point to that instead of `v1.30.0`).
159
160
+## Adding extra packages at runtime
161
+
162
+By default, the official Netdata container images do not include a number of optional runtime dependencies. You
163
+can add these dependencies, or any other APK packages, at runtime by listing them in the environment variable
164
+`NETDATA_EXTRA_APK_PACKAGES`.
165
+
166
+Commonly useful packages include:
167
+
168
+- `apcupsd`: For monitoring APC UPS devices.
169
+- `libvirt-daemon`: For resolving cgroup names for libvirt domains.
170
+- `lm-sensors`: For monitoring hardware sensors.
171
+- `msmtp`: For email alert support.
172
+- `netcat-openbsd`: For IRC alert support.
173
+
174
## Health Checks
175
176
Our Docker image provides integrated support for health checks through the standard Docker interfaces.
packaging/docker/run.sh
+13
@@ -67,4 +67,17 @@ if [ -n "${NETDATA_CLAIM_URL}" ] && [ -n "${NETDATA_CLAIM_TOKEN}" ] && [ ! -f /v
67
-daemon-not-running
68
fi
69
70
+if [ -n "${NETDATA_EXTRA_APK_PACKAGES}" ]; then
71
+ echo "Fetching APK repository metadata."
72
+ if ! apk update; then
73
+ echo "Failed to fetch APK repository metadata."
74
+ else
75
+ echo "Installing supplementary packages."
76
+ # shellcheck disable=SC2086
77
+ if ! apk add --no-cache ${NETDATA_EXTRA_APK_PACKAGES}; then
78
+ echo "Failed to install supplementary packages."
79
+ fi
80
+ fi
81
+fi
82
+
83
exec /usr/sbin/netdata -u "${DOCKER_USR}" -D -s /host -p "${NETDATA_LISTENER_PORT}" "$@"