I have two separate services, in different directories, configured for the same docker network.
Service PUB is a RabbitMQ publisher. Its docker-compose file starts service PUB and RabbitMQ.
Service WRK is a RabbitMQ worker. Its docker-compose file starts service WRK and RabbitMQ.
docker-compose up -d PUB will start PUB and RabbitMQ, but then running docker-compose up -d WKR will fail, as the RabbitMQ port is already allocated. Bind for 0.0.0.0:15672 failed: port is already allocated
However, docker-compose up -d WRK starts both WRK and RabbitMQ, if I haven't already started PUB.
How do I configure the docker-compose.yml files so that if RabbitMQ is already running, it doesn't attempt to start RabbitMQ and just connects to the existing instance?
docker-compose.yml for service PUB:
services:
  PUB:
    image: pub-image
    networks:
      - myNet
    environment:
      RMQ_URI: amqp://guest@rabbitmq:5672//
    ports:
      - 127.0.0.1:5000:5000/tcp
    links:
      - rabbitmq:rabbitmq
    depends_on:
      - rabbitmq
  rabbitmq:
    image: rabbitmq:3.8.14-management
    networks:
      - myNet
    ports:
      - 5672:5672
      - 15672:15672
networks:
  myNet:
    name: myNet
    driver: bridge
docker-compose.yml for service WRK:
services:
  WRK:
    image: wrk-image
    networks:
      - myNet
    environment:
      RMQ_URI: amqp://guest@rabbitmq:5672//
    links:
      - rabbitmq:rabbitmq
    depends_on:
      - rabbitmq
  rabbitmq:
    image: rabbitmq:3.8.14-management
    networks:
      - myNet
    ports:
      - 5672:5672
      - 15672:15672
networks:
  myNet:
    name: myNet
    driver: bridge
 
    