Connecting to RabbitMQ container with docker-compose

前端 未结 2 704
一个人的身影
一个人的身影 2021-02-05 19:45

I want to run RabbitMQ in one container, and a worker process in another. The worker process needs to access RabbitMQ.

I\'d like these to be managed through docker-

2条回答
  •  我在风中等你
    2021-02-05 20:04

    Maybe you dont need to expose/map the ports on the host if you are just accessing the service from another container.

    From the documentation:

    Expose Expose ports without publishing them to the host machine - they’ll only be accessible to linked services. Only the internal port can be specified.

    expose:
     - "3000"
     - "8000"
    

    So it should be like this:

    version: "3"
    
    services:
    
      rabbitmq:
        image: rabbitmq
        command: rabbitmq-server
        expose:
          - "5672"
          - "15672"
    
      worker:
        build: ./worker
        depends_on:
          - rabbitmq
        # Allow access to docker daemon
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
    

    also make sure to connect to rabitmq only when its ready to server on port.

提交回复
热议问题