Is it possible to change the ECS container hostname without restart

0

I am new to ecs and I am trying to migrate our java micro service application into containers. I chose ECS EC2 launch type Cluster because of simplicity, cost effective and for long time running of computes.

I have problem have a issue with Eureka(discovery) server and client machines. like basically eureka resisters the client machines with hostname when we hosted our application before containerization. Host name of EC2 machine is private DNS and communication between each service is happening without any issue.

Now the eureka server is registering the clients with container id and we are not able to communicate with each other service. If we select network-mode host then its working fine and if we chose bridge network then it's not working because of the container hostname is container id.

Guide me to set the hostname dynamically when the container starts or please suggest the recommended approach in order to work with this scenario

1 Answer
0

When using Fargate launch type on ECS, the containers will have random IDs assigned instead of stable hostnames. Eureka relies on hostnames, so it won't work out of the box.

You have a few options to set stable hostnames for the containers:

  • Use ECS tasks definitions to assign hostnames via hostname parameter
  • Configure ECS tasks to use AWS Elastic Network Interfaces (ENIs) which provide static IPs/hostnames
  • Use service discovery solutions like AWS Cloud Map or Consul which are better integrated with ECS

For simple testing, you can try using the host network mode instead of bridge to assign the EC2 hostname to containers. However, this tightly couples containers to hosts.

Make sure your Eureka clients are configured to register using IP addresses instead of hostnames for high availability on ECS/Fargate.

Consider alternative service discovery solutions like AWS Cloud Map or Consul that are better integrated for container-based workloads on ECS.

profile picture
EXPERT
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions