When I was try to commit Elasticsearch container and run image again Elasticsearch credential not working and data was also lost in new container.Why its happening ?
You need top share your compose or how you are running Elasticsearch.
Are you using a persistent volume? If you do not use a persistent volume docker containers will not keep your data when you stop them.
I took base container of elk [https://hub.docker.com/r/sebp/elk/] and do some configuration related to xpack security and logstash and push some data in Elasticsearch than I commit and export container image and when I import and run again existing password is not working and all data of Elasticsearch was loss.
You need to share how you are running it.
Please share your docker command or docker-compose.
It is impossible to have a hint of what could be the issue without this information.