Choosing primary when creating a replica set

I wrote an init.sh file to create sharded Mongo DB containers. I want to prioritize my replicas as I wish. but I’m getting an error.
init.sh :

``

cd server215/configsvr
pwd
docker-compose up -d
export IP_ADDRESS=172.16.187.128
echo $IP_ADDRESS
``

check_container_health configsvr_mongo1
echo "ilk kontrol"

sudo systemctl enable mongod
sudo systemctl start mongod
docker exec -it configsvr_mongo1 mongosh --eval 'rs.status();'
docker exec -it configsvr_mongo1 mongosh --eval 'rs.initiate({ _id: "cfgrs", configsvr: true, members: [{ _id : 0, host :"'$IP_ADDRESS':40001" },{ _id : 1, host : "'$IP_ADDRESS':40002" },{ _id : 2, host : "'$IP_ADDRESS':40003" },]});'

docker exec -it configsvr_mongo1 mongosh --eval 'rs.status();'

and my error is :

> MongoServerError: No host described in new configuration with {version: 1, term: 0} for replica set cfgrs maps to this node

and my docker-compose.yml is :

version: '3.8'

services:
  mongo1:
    container_name: configsvr_mongo1
    image: mongo:6.0
    networks:
      - mongo-network
    ports:
      - 40001:27017
    restart: always
    depends_on:
      - mongo2
      - mongo3
    links:
      - mongo2
      - mongo3
    command: mongod --auth --configsvr --replSet cfgrs --port 27017 --dbpath /data/db --keyFile keyFile
    volumes:
      - ../../../storage-data/configsvr_mongo1:/data/db
      - /home/rumeysa/Desktop/installation/app/database/sharded/keyFile:/keyFile
    healthcheck:
      test: ['CMD', 'mongosh', '--eval', "db.adminCommand('ping')"]
      interval: 10s
      timeout: 5s
      retries: 5
    labels:
      maintainer: ino
      description: mongo-configsvr
      project: pms
      version: v1.0.0
      type: database
    logging:                  # Add this section for logging configuration
      driver: "json-file"     # Here, we're using the json-file driver for logging
      options:
        max-size: "2g"        # Set the maximum size for a log file (2 gigabyte)
        max-file: "5"         # Set the maximum number of log files to keep
   


  mongo2:
    container_name: configsvr_mongo2
    image: mongo:6.0
    networks:
      - mongo-network
    ports:
      - 40002:27017
    restart: always
    command: mongod --configsvr --replSet cfgrs --port 27017 --dbpath /data/db --auth --keyFile keyFile
    volumes:
      - ../../../storage-data/configsvr_mongo2:/data/db
      - /home/rumeysa/Desktop/installation/app/database/sharded/keyFile:/keyFile
    healthcheck:
      test: ['CMD', 'mongosh', '--eval', "db.adminCommand('ping')"]
      interval: 10s
      timeout: 5s
      retries: 5
    labels:
      maintainer: ino
      description: mongo-configsvr
      project: pms
      version: v1.0.0
      type: database
    logging:                  # Add this section for logging configuration
      driver: "json-file"     # Here, we're using the json-file driver for logging
      options:
        max-size: "2g"        # Set the maximum size for a log file (2 gigabyte)
        max-file: "5"         # Set the maximum number of log files to keep

  mongo3:
    container_name: configsvr_mongo3
    image: mongo:6.0
    networks:
      - mongo-network
    ports:
      - 40003:27017
    restart: always
    command: mongod --configsvr --replSet cfgrs --port 27017 --dbpath /data/db --auth --keyFile keyFile
    volumes:
      - ../../../storage-data/configsvr_mongo3:/data/db
      - /home/rumeysa/Desktop/installation/app/database/sharded/keyFile:/keyFile
    healthcheck:
      test: ['CMD', 'mongosh', '--eval', "db.adminCommand('ping')"]
      interval: 10s
      timeout: 5s
      retries: 5
    labels:
      maintainer: ino
      description: mongo-configsvr
      project: pms
      version: v1.0.0
      type: database
    logging:                  # Add this section for logging configuration
      driver: "json-file"     # Here, we're using the json-file driver for logging
      options:
        max-size: "2g"        # Set the maximum size for a log file (2 gigabyte)
        max-file: "5"         # Set the maximum number of log files to keep

volumes:
  configsvr_mongo1: ~
  configsvr_mongo2: ~
  configsvr_mongo3: ~

networks:
  mongo-network:
    driver: bridge