Why i can't do curl when i have two docker-compose yml file

I have two yaml file (docker-compose.yml and cluster.yml) both these yml files has different network
The objective of this file is
I have to create two different zone cluster for R&D. Containers are running fine but when i did curl it show me peer reset

I am attaching link
https://stackoverflow.com/questions/75636733/issue-in-running-multiple-docker-compose-yaml-file

Can anyone help me ?

Hint: A topic usually gets more attention if all relevant details are shared in the original post. No one likes to follow links (for instance: I never click them) to gather information.

I have created two docker-compose files(docker-compose.yml and cluster.yml .

docker-compose.yml

version: '2.2'
services:
  dcnode_1:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
    container_name: dcnode_1
    environment:
      - cluster.name=dc_elastic
      - node.name=dcnode_1
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - bootstrap.memory_lock=true
      - node.roles=master,data
      - discovery.seed_hosts=dcnode_1,dcnode_2,dcnode_3
      - cluster.initial_master_nodes=dcnode_1,dcnode_2,dcnode_3
    logging:
      driver: "json-file"
      options:
        max-file: "9"
        max-size: "6m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    restart: always
    volumes:
      - dcdata_1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      dc_network:


  dcnode_2:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
    container_name: dcnode_2
    environment:
      - cluster.name=dc_elastic
      - node.name=dcnode_2
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - node.roles=master,data
      - bootstrap.memory_lock=true
      - discovery.seed_hosts=dcnode_1,dcnode_2,dcnode_3
      - cluster.initial_master_nodes=dcnode_1,dcnode_2,dcnode_3
    logging:
      driver: "json-file"
      options:
        max-file: "9"
        max-size: "6m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    restart: always
    volumes:
      - dcdata_2:/usr/share/elasticsearch/data
    networks:
      dc_network:

  dcnode_3:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
    container_name: dcnode_3
    environment:
      - cluster.name=dc_elastic
      - node.name=dcnode_3
      - node.roles=master,data
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - bootstrap.memory_lock=true
      - discovery.seed_hosts=dcnode_1,dcnode_2,dcnode_3
      - cluster.initial_master_nodes=dcnode_1,dcnode_2,dcnode_3
    logging:
      driver: "json-file"
      options:
        max-file: "9"
        max-size: "6m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    restart: always
    volumes:
      - dcdata_3:/usr/share/elasticsearch/data
    networks:
      dc_network:


networks:
  dc_network:
    external:
      name: dc_network

volumes:
  dcdata_1:
    driver: local
  dcdata_2:
    driver: local
  dcdata_3:
    driver: local

cluster.yml

version: '2.2'
services:
  drnode_1:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
    container_name: drnode_1
    environment:
      - cluster.name=dr_elastic
      - node.name=drnode_1
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - bootstrap.memory_lock=true
      - node.roles=master,data
      - discovery.seed_hosts=drnode_1,drnode_2,drnode_3
      - cluster.initial_master_nodes=drnode_1,drnode_2,drnode_3
    logging:
      driver: "json-file"
      options:
        max-file: "9"
        max-size: "6m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    restart: always
    volumes:
      - drdata_1:/usr/share/elasticsearch/data
    ports:
      - 9201:9201
    networks:
      dr_network:


  drnode_2:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
    container_name: drnode_2
    environment:
      - cluster.name=dr_elastic
      - node.name=drnode_2
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - node.roles=master,data
      - bootstrap.memory_lock=true
      - discovery.seed_hosts=drnode_1,drnode_2,drnode_3
      - cluster.initial_master_nodes=drnode_1,drnode_2,drnode_3
    logging:
      driver: "json-file"
      options:
        max-file: "9"
        max-size: "6m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    restart: always
    volumes:
      - drdata_2:/usr/share/elasticsearch/data
    networks:
      dr_network:

  drnode_3:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
    container_name: drnode_3
    environment:
      - cluster.name=dr_elastic
      - node.name=drnode_3
      - node.roles=master,data
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - bootstrap.memory_lock=true
      - discovery.seed_hosts=drnode_1,drnode_2,drnode_3
      - cluster.initial_master_nodes=drnode_1,drnode_2,drnode_3
    logging:
      driver: "json-file"
      options:
        max-file: "9"
        max-size: "6m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    restart: always
    volumes:
      - drdata_3:/usr/share/elasticsearch/data
    networks:
      dr_network:


networks:
  dr_network:
    external:
      name: dr_network

volumes:
  drdata_1:
    driver: local
  drdata_2:
    driver: local
  drdata_3:
    driver: local

I have created this 2 networks manually by running docker network create dr_network same for dc_network.

All 6 containers are running from these two yaml file(docker-compose.yml and cluster.yml)

But i am getting error when i do curl docker-compose -f cluster.yml up -d

[root@localhost docker]# curl -XGET "http://127.0.0.1:9201/_cat/shards?pretty"
curl: (56) Recv failure: Connection reset by peer
[root@localhost docker]#

and for 2nd compose file that is docker-compose.yml it is working(when i do curl)

Since I can’t see any environment variable used to change the port Elasticsearch is running inside the container, It appears that this port mapping points to a wrong container port.

If I am right, then changing the mapping from 9201:9201 to 9201:9200 should fix the issue. Once the change is deployed, your curl command should reach the port inside the container.

Hi @meyay

Thank you but i am understanding this 9201:9200 earlier i was using 9201:9201
it should work

Could you please tell me the reason why we change the port like 9201 : 9200 is it different from 9201:9201

You might want to make it a habit to look up configuration elements in the compose file specification if you are unclear how to use them.

Here is the direct link to the ports section:

Your compose file uses the short Syntax:

I must admit, am slightly confused about this question. Please let us know, why you feel that mapping the host port to the container port 9201 instead of 9200 (the port the application is listening inside the container) should have worked. What did you actually do, to make the application inside the container listen on port 9201?

With bridge and overlay networks, there is no need to ever change the container port (right hand side of the port mapping). It is required to change the host ports (left hand side of the port mapping), as a port can only bound once per ip. Do not change the container port in a mapping, unless you know what you are doing and why you are doing it.

Furthermore, I can highly recommend this free self-paced docker training. It will give you a solid understanding of docker concepts and how things are done in docker.