/etc/hosts file is not updated, using docker-compose file

It seems this is related to your compose file version:

If you’re using a version 2 Compose file, no /etc/hosts entries will be created. This is not a bug. Version 2 files make use of Docker networking, which uses DNS instead of /etc/hosts to resolve hostnames.

Reference: Adding new link does not update /etc/hosts with name specified in docker-compose.yml · Issue #2038 · docker/compose · GitHub