Amazon Linux 2 in a Docker missing hostname command

0

We're developing an app running in a Docker container: on-premises, so this question is purely about Amazon Linux 2 and has nothing to do with AWS.

I'm migrating the image from the one based on centos:7 to amazoncorretto:17, based on amazonlinux:2. Surprisingly, hostname -f, which is used to get an FQDN inside a container, is failing because Amazon Linux 2 doesn't have hostname.

We do need the host FQDN, and it gets propagated to containers either via host networking or via Docker's Swarm --hostname {{.Node.Hostname}}, etc.

I have two questions:

  1. How do I get an FQDN without hostname?
  2. Why did Amazon Linux 2 remove it? Even Alpine has it. Would it make sense to put it back?
profile picture
DK
질문됨 2년 전698회 조회
1개 답변
1
수락된 답변

Hi,

You can get the hostname command using yum

yum install hostname

Another alternative would be to build your own customized image from amazoncorretto:17 with hostname preinstalled so as to avoid the need for any install during runtime.

--Syd

profile picture
Syd
답변함 2년 전
profile picture
전문가
검토됨 하루 전
  • Yes, this seems to be the easiest fix.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠