Not able to update static/default Hostname/IP for my "/etc/hosts" file inside my linux( Centos7) docker container

Not able to update static/default Hostname/IP in “/etc/hosts” file inside my linux( Centos7) docker container.

how can i set other hostnames and ips in “/etc/hosts” file of my new docker container dynamically once its started ?

Help is appreciated. Thanks in advance.
Regards,
Shahid

Static changes are done using: https://docs.docker.com/compose/compose-file/#extra_hosts

Why would you want to add containers dynamicly? On standalone docker --link takes care of this. On docker-compose and Swarm the docker networks dns-server takes care of this - the servicename is registered as hostname and can be used from other containers to access it.

@meyay thanks for your response…in my case i will be running three docker containers, i know which ip address it will take by default (172.17.0.* etc). i want to update those ip with hostname in /etc/hosts becoz i want them communicate without password.

What do you mean by commincate without password?

If you try to access a container by its container ip, then you high likely do something fundamentaly wrong.

see im using container as a OS (centos7) i want all my containers should communicate wit each other becoz im going to deploy my app over there for that i need all instance to b communicate without password. everythng has set but the only problem is i need to add ip and hostname manually, this is what im trying to avoide…thanks

What I wrote above works with single and/or multi host multi container deployments. So what makes your scenario so special that the generaly working approach does not apply for you?!

You neither explained the password situation, nor why this relates to centos7.