'Elastic search container on docker refusing connection

I am trying to run logstash with elastic search by executing following command

docker run --name ls01 --net elastic -p 9600:9600 -it logstash:8.2.0 -e 'input{
   stdin{
   }
}

output{
elasticsearch{
    hosts => ["https://localhost:9200"]
    index => "hello-logstash-docker"
 }
}'

But elastic search is refusing connection, I am receiving following error. Attempted to resurrect connection to dead ES instance, but got an error {:url=>"http://elasticsearch:9200/", :exception=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :message=>"Elasticsearch Unreachable: [http://elasticsearch:9200/][Manticore::ResolutionFailure] elasticsearch: Name or service not known"}

I am using elasticsearch version 8.2.0



Sources

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

Source: Stack Overflow

Solution Source