Cannot access with Dockerfile, only if I use a image?

Hi,
I´m a Docker newbie:

I have a docker-compose file like:

  elasticsearch:
    image: docker. elastic. co/ elasticsearch/elasticsearch:8.15.0
    #build:
    #  context: ${ROOT_DIR!}/elasticsearch
    container_name: elasticsearch
    environment:
      - discovery.type=single-node
      - ES_JAVA_OPTS=-Xms512m -Xmx512m
      - "ELASTIC_PASSWORD=${ELASTICSEARCH_PASSWORD}"
      - "xpack.security.enabled=false"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - ${ROOT_DIR}/elasticsearch:/elasticsearch
      - elasticsearch_data:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"
    networks:
      - app-network

If I use this, I can access http:// localhost: 9200/

But if I change it to a build with Docker File:

 elasticsearch:
    build:
      context: ${ROOT_DIR}/elasticsearch
      dockerfile: Dockerfile

and here my Docker File:

FROM docker.elastic.co/elasticsearch/elasticsearch:8.15.0

COPY setup_template_wildfly.sh /usr/share/elasticsearch/setup_template_wildfly.sh

RUN ls -l /usr/share/elasticsearch/setup_template_wildfly.sh

USER root

RUN chmod +x /usr/share/elasticsearch/setup_template_wildfly.sh

USER elasticsearch

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

CMD ["sh", "-c", "/usr/share/elasticsearch/setup_template_wildfly.sh && elasticsearch"]

That´s my script to execute:

#!/bin/bash

# Warte, bis Elasticsearch gestartet ist
until curl -s http://localhost:9200 >/dev/null; do
  echo "Warte auf Elasticsearch..."
  sleep 5
done

# Füge das Index Template hinzu
curl -X PUT "http://localhost:9200/_index_template/wildfly-template" -H 'Content-Type: application/json' -d'
{
  "index_patterns": ["wildfly-logs-*"],
  "template": {
    "mappings": {
      "properties": {
        "@timestamp": {
          "type": "date"
        },
        "log.level": {
          "type": "keyword"
        },
        "message": {
          "type": "text"
        }
      }
    }
  }
}

I cannot acccess.
The build seems fine, there is no error.
In the Elasticsearch log I can find only from the script…:

2024-08-20 13:24:34 Warte auf Elasticsearch…

I have no idea, what´s wrong?
(Some links has been adjusted with a space, otherwise I couldn´t post it)