'Cannot access localhost:8080 using alias in docker compose

Im looking to access localhost:8080 using alias inside docker-compose.yml. I tried those 2 options :

build: .
networks:
    default:
      aliases:
        - localhost:8080

extra_hosts:
  - localhost:8080

But infortunately it's not working at all. Any suggestions ??



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source