To use Elasticsearch and Grafana in a local environment, start by creating a shared network using Docker and the command 'docker network create monitoring'.
Next, start the Elasticsearch container by running the command 'docker run -d --name=elasticsearch --network=monitoring -p 9200:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:8.12.0'.
Check if Elasticsearch is running by using the command 'curl -X GET "http://localhost:9200"'.
Finally, start the Grafana container using the command 'docker run -d --name=grafana --network=monitoring -p 3003:3000 grafana/grafana'. Access Grafana at http:localhost:3003 and configure Elasticsearch in Grafana to view logs.