0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-13 17:19:11 +00:00

docker: use /host/etc/hostname if mounted ()

This commit is contained in:
Ilya Mashchenko 2023-11-16 17:09:06 +02:00 committed by GitHub
parent cd82944a89
commit 5344c11728
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions
daemon
packaging/docker

View file

@ -1054,16 +1054,32 @@ static void backwards_compatible_config() {
}
static int get_hostname(char *buf, size_t buf_size) {
if (netdata_configured_host_prefix && *netdata_configured_host_prefix) {
char filename[FILENAME_MAX + 1];
snprintfz(filename, FILENAME_MAX, "%s/etc/hostname", netdata_configured_host_prefix);
if (!read_file(filename, buf, buf_size)) {
trim(buf);
return 0;
}
}
return gethostname(buf, buf_size);
}
static void get_netdata_configured_variables() {
backwards_compatible_config();
// ------------------------------------------------------------------------
// get the hostname
netdata_configured_host_prefix = config_get(CONFIG_SECTION_GLOBAL, "host access prefix", "");
verify_netdata_host_prefix();
char buf[HOSTNAME_MAX + 1];
if(gethostname(buf, HOSTNAME_MAX) == -1){
if (get_hostname(buf, HOSTNAME_MAX))
netdata_log_error("Cannot get machine hostname.");
}
netdata_configured_hostname = config_get(CONFIG_SECTION_GLOBAL, "hostname", buf);
netdata_log_debug(D_OPTIONS, "hostname set to '%s'", netdata_configured_hostname);
@ -1163,10 +1179,6 @@ static void get_netdata_configured_variables() {
default_rrd_memory_mode = RRD_MEMORY_MODE_SAVE;
}
#endif
// ------------------------------------------------------------------------
netdata_configured_host_prefix = config_get(CONFIG_SECTION_GLOBAL, "host access prefix", "");
verify_netdata_host_prefix();
// --------------------------------------------------------------------
// get KSM settings

View file

@ -453,9 +453,9 @@ above section on [configuring Agent containers](#configure-agent-containers) to
how you created the container.
Alternatively, you can directly use the hostname from the node running the container by mounting `/etc/hostname` from
the host in the container. With `docker run`, this can be done by adding `--volume /etc/hostname:/etc/hostname:ro` to
the host in the container. With `docker run`, this can be done by adding `--volume /etc/hostname:/host/etc/hostname:ro` to
the options. If you are using Docker Compose, you can add an entry to the container's `volumes` section
reading `- /etc/hostname:/etc/hostname:ro`.
reading `- /etc/hostname:/host/etc/hostname:ro`.
## Adding extra packages at runtime