Skip to content

bug: can not get hostname in redhat #12270

Open
@xuruidong

Description

@xuruidong

Current Behavior

apisix.core.utils.gethostname returns "" in apache/apisix:3.11.o-redhat, not the hostname or string “unknow”

Expected Behavior

The apisix.core.utils.gethostname function returns the correct hostname in systems where '/bin/hostname' is not present.

Error Logs

2025/05/30 02:35:24 [warn] 51#51: *1 [lua] plugin.lua:957: decrypt_conf(): failed to get schema for plugin: zero-trust-auth, context: init_worker_by_lua*
2025/05/30 02:35:24 [warn] 51#51: *1 [lua] plugin.lua:957: decrypt_conf(): failed to get schema for plugin: idaas-cas, context: init_worker_by_lua*
2025/05/30 02:35:24 [warn] 51#51: *1 [lua] plugin.lua:957: decrypt_conf(): failed to get schema for plugin: zero-trust-auth, context: init_worker_by_lua*
sh: /bin/hostname: No such file or directory

Steps to Reproduce

  1. git clone https://github.com/apache/apisix-docker.git
  2. cd apisix-docker/example
  3. modify apisix docker image to apache/apisix:3.11.0-redhat in apisix-docker/example/docker-compose.yml
services:
  apisix:
    image: apache/apisix:${APISIX_IMAGE_TAG:-3.11.0-redhat}

BTW, the "apache/apisix:3.12.0-redhat" does not exist.

  1. docker-compose -p apisix up -d
  2. docker logs -f apisix-apisix-1 , you will see 'sh: /bin/hostname: No such file or directory' in the log
  3. curl http://127.0.0.1:9092/v1/server_info , you will see the hostname is ""
    {"boot_time":1748572529,"etcd_version":"3.5.0","id":"eb7f4459-4920-4555-9fe9-833a4babb889","version":"3.11.0","hostname":""}
    
 

### Environment

- APISIX version (run `apisix version`):  3.11.0
- Operating system (run `uname -a`):
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
- etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
- APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run `luarocks --version`):

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions